Originally Posted by
Rodaxoleaux
Also, why do people keep using assignments with char[] arrays instead of char* pointers. In my usage, char[] has caused me nothing but trouble.
Maybe an area of C you should work on . They're actually called initializers, not assignments (they must be part of the variable definition). You can't assign to an array with = in C. As for char *, they aren't all that helpful if you want to change the contents. String constants should be just that, constant. Most modern implementations store them in an unwritable segment of memory. On many systems, the following would seg fault:
Code:
char *victim_name = "Jon Doe"; // points to a string constant, probably stored somewhere in unwritable memory
if (victim_identified)
strcpy(victim_name, "Fred Flintstone"); // oops, can't copy into unwritable memory, seg fault
whereas the following would work
Code:
char victim_name[MAX_NAME] = "Jon Doe";
if (victim_identified)
strcpy(victim_name, "Fred Flintstone");
Sure, there are ways around the char * issues, like pointing victim_name to a char array or malloc'ing some memory for it, but that doesn't always make them the best solution.