Incompatible format types
- by nebffa
I'm playing around with strncpy in C and am having some trouble.
The code is as follows:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char src[] = "Benjamin Franklin";
char dest[5];
strncpy(src, dest, sizeof(dest) / sizeof(char));
dest[5] = '\0';
printf("%s\n", dest);
return 0;
}
which compiles with no errors using:
gcc -Wall -g -Werror test.c -o test
and prints out gibberish like
p4??
I cannot really understand what I'm doing wrong especially since I have played around with it a lot and been looking online for answers. Perhaps since I am using arrays I am passing the address to printf without realising it?