If you could help me, that would be much appreciated. This code is about my thesis. I'm trying to write to a file and it works but when I try to read another file it reads incorrectly. For example, the file I want to read has 5 in it, but it reads as 1. I tried to write different numbers into the file but it is constantly being read 1. Another problem is that I have to read more than one group of data in this file. That is, it will read different variables. For example, I have a data file, it will read the distance matrix first, it will read the cost matrix when it is finished. Then it will read demand array. I mean, I have to read something new on the new line. How can I do? Help me please.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
FILE* myfile;
errno_t errorcode = fopen_s(&myfile, "output.txt", "w");
if (myfile == NULL)
{
printf("Error");
}
FILE* data;
errno_t err = fopen_s(&data, "C:\\SA\\input.txt", "r");
if(data==NULL)
{
printf("file does not open");
}
int s;
while (!feof(data))
{
s = fscanf_s(data, "%d", &s);
printf("s:%d", s);
}
float dist[15][15], y1, y2, x1, x2;
dist[15][15] = sqrt(pow((y2-y1),2)+pow((x2-x1),2));
return 0;
getchar();
}