[chbot] C prinf() %s

hamster hamster at snap.net.nz
Tue Nov 22 03:08:14 GMT 2011


On Tue, 22 Nov 2011 16:03:36 +1300, hamster <hamster at snap.net.nz> wrote:
> You could try something like
> printf("%*.*s",strlen(str)-1,strlen(str)-1,str) to limit your output.
> 
> Or you could  fwrite(str,strlen(str)-1,1,stdout) to write all but the
last
> byte.
> 

Hi Jimmy

(Replying to self... such bad form!)

$ cat main.c

#include <stdio.h>
#include <string.h>

int main(int c, char *v[])
{
  char str[] = "Hello\n";
  printf("%*.*s world\n",strlen(str)-1,strlen(str+1), str);
}

$ gcc -o main main.c
$ ./main
Hello world
$




More information about the Chchrobotics mailing list