File input output help in C.

I'm making a program to sort a file by city and outputting to a different file. I have a structure with 7 character arrays. I'm reading from a file that contains 10 lines of information.First name, last name, address, city, state, zip, phone all separated by a tab.

Gary Paul 3129 Philadelphia Avenue Murray Utah 84107 8012882141

I input each line with fgets as another character array. I then use strtok() to separate it into each piece of info as such. line is a character array, pch is just a pointer, delim is a definition of "\t\n", and temp is an instance of the structure

pch = strtok(line, delim);
strcpy(temp.first, pch);

pch = strtok(NULL, delim);
strcpy(temp.last, pch);

pch = strtok(NULL, delim);
strcpy(temp.address, pch);

pch = strtok(NULL, delim);
strcpy(temp.city, pch);

pch = strtok(NULL, delim);
strcpy(temp.state, pch);

pch = strtok(NULL, delim);
strcpy(temp.zip, pch);

pch = strtok(NULL, delim);
strcpy(temp.phone, pch);

pch = strtok(NULL, delim);

I see nothing wrong with this but when i try to output these to the output file, it just comes up as a mess of accented 'i's and random words in the file. Any help would be appreciated.

Posted May 26, 2015, 3:58 AM UTC

04
Loading comments…