Again, I have to disagree with you there. While I'll agree that both methods may have drawbacks, lets see which error is easier to spot:I think that that is bad advice in this case -> Think about this example
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #define STR_MAX 16 int main(void) { char a[]="Giovani"; char b[]="Loserone+_+"; strcpy(a,b); ...
vs.Code:/* You can visually see that b is longer then a */ char a[] = "Some string here"; char b[] = "Some longer string here"; ... strcpy(a, b);
When you see an array declared with a set size, you assume that the coder knew the correct size, you're not going to manually count the length of the string and ensure there is enough space for the literal they are initializing with. Above the first string a[] has ALMOST enough space, except for the trailing NULL which is an extremely easy mistake to make. Not to mention b[] is off by about 3-4 chars (but can you tell that instantly, by visually looking at it?)Code:char a[16] = "some string here"; char b[16] = "some other string"; ... strcpy(a, b);