Hi vart, thanks for taking the time to help me. I think I've done as you suggested, as noted in the revised code below. However I'm getting another set of strange results. The 'while' loop is still printing fine. However the 'for' loop isn't working still. The numbers print, but the words are prefixed with the first letter of each word. I've commented it below the main program. I've tried various declarations, referencing, and dereferencing of pointers, and getting rid of them all together to no avail. I'm certain I'm doing something wrong, but what?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* 1 one
2 two
3 three
4 four
5 five
6 six
*/
int main()
{
FILE *myfile;
char line[121];
char *item;
int reccount=0;
int temp_num[10];
char temp_name[10];
int x;
myfile=fopen("C:\\Users\\eric\\Desktop\\c_code\\number_exp.txt","r");
while(fgets(line,120,myfile))
{
printf("%s",line);
item=strtok(line," ");
temp_num[reccount]=atoi(item);
item=strtok(NULL," ");
strcpy(&temp_name[reccount],item);
reccount++;
}
fclose(myfile);
for(x=0;x<reccount;x++)
printf("%i %s",temp_num[x],&temp_name[x]);
return 0;
}
/* 1 one
2 two
3 three
4 four
5 five
6 six
1 ottffsix
2 ttffsix
3 tffsix
4 ffsix
5 fsix
6 six
*/