okay, i'm new to C and going crazy trying to understand this little problem.
in the code below, example A doesn't work, while B does. why is this so?
i thought that declaring strings by "char *blah" and "char blah[]" would essentially be the same since arrays are just pointers anyway. am i wrong?
the reason i ask this is because i'm writing a function that needs to use strings which aren't initialized with a value and hence need to have the array size automatically known ("char *blah;" works for this while "char blah[];" gives an array size unknown error).
after all this, i then want the strings to be passed to strcat() for concatenation.
i really hope someone can help here.. thanks.
// EXAMPLE A
#include <stdio.h>
#include <string.h>
main()
{
char *yr="1985";
char *car=" toyota";
strcat(yr, car);
printf("%s", yr);
}
// EXAMPLE B
#include <stdio.h>
#include <string.h>
main()
{
char yr[]="1985";
char car[]=" toyota";
strcat(yr, car);
printf("%s", yr);
}