I have created my program, however we have just been introduced to text files. I can get my code to read the file however, I have tried everything to get it to scan the file and store the data into variables, and still have no luck.
My text files resembles the following...
4 6000
3 9
5 60
7.00 800.00
2.00 6000.00
Code:
char t1[6], t2[6], t3[6], t4[6], t5[6], t7[6], t8[6], t9[6], t10[6];
FILE *tp;
tp = fopen("report.txt", "rt");
if (tp == NULL)
{
printf("Error opening source file\n");
perror("Error opening report.txt");
getchar();
}
else
{
while (fscanf(tp, "%d%d%d%d%d%s%lf%lf%lf%lf", &t1, &t2, &t3, &t4, &t5, &t6, &t7, &t8, &t9, &t10) != EOF)
{
printf("%d", t1); // wanted to see if it would print '4' my first number in text file.
fclose(tp);
}
}