Modifying strings in a string array in C -
this problem... created array of strings this..
char *name[12]; then user types 12 different names can save them in array. known if don't initialize variable has 'garbage' in it. started saving names correctly until 5th name, crashes, don't know why. tried initialize every element doesn't allow me change content.
this how write every element of array:
printf("type name: "); fflush(stdin); gets( name[0] ); //i use move every element and want know if there's way initialize array, , change it's content after that. i've tried strcpy(); had same error. or how delete 'garbage' stop causing me errors.
thanks, , sorry if had misspelling. english not native language.
the problem have array of char pointers, haven't initialised them or allocated space them in way. don't know happen when use address points to.
you have loop through array , initialise elements before can use them.
name[0] = malloc (size); you can try reading user input buffer length of data entered, mallocating correct amount of space, or having pre-defined chunk of memory allocate before using it.
Comments
Post a Comment