I am reading a line from files containing names of people, names of men in the first line, and names in the second line I want to store these names in two arrays, for a man, for a woman, though, when I print them, I get strange things. I am not sure if I have them properly I am not reading or wrongly A. I am impressed so
Four line [100]; // read the line * items; // Four Items in a Line * Item 2; Int participants = 5; Number of people in the event / number * male name [participants]; Four * female names [participants]; Fgets (line, 255, file); Int i; Item = strotok (line, ""); For (i = 0; i & lt; affiliates; i ++) {male name [i] = items; Item = stroke (NULL, ""); } // Reading female name is now fgets (line, 1024, file); Item2 = strtok (line, ""); (I = 0; i & lt; affiliates; i ++) for {female name [i] = item 2; Item 2 = stroke (NULL, "");
These rows are read
John Jeffery Adam Mark Peter Jenny Alice Sally Wendy Amanda
But when I Print them like this:
For (i = 0; i & lt; affiliates; i ++) {printf ("% s% s \ n", male name [i] , Female name [i]);
I get a lot:
Jenny Jenny Alice colleague Sally Wendy Vendée Amanda
Note: If I After reading the names of the females print the names of the men after reading, then they are properly printed
If you do not pay attention to other problems (such as size, 255 and 1024, when you are only 100 characters long buffer, then you pass through the fatway) It is likely that you are using the same buffer, four line [100], both fgets () strokes for calls An indicator for a character in line buffer So, when you store female names in the "row", then all these pointers, relative to the line, when men in the line are named, are now invalid, try to accumulate the female line in other buffers; should work.
EDIT: Sorry, if "not paying attention ..." is not far away from my intentions to demolish the sounds, everybody makes a mistake at all times, especially on learning. I wish you luck with the process :)
Comments
Post a Comment