Hi guys, I have this input.txt file and I have to scan it to get information for my project.
the input.txt file has format as:
33 56 34.8 N
118 24 30.1 W
37 40 23.5 S
144 50 54.1 E
So I used fscanf_s to scan the file. Here is my code
int long1deg,long1min,long1sec,lat1deg,lat1min,lat1sec;
int long2deg,long2min,long2sec,lat2deg,lat2min,lat2sec;
char orien1lon[2], orien1lat[2],orien2lon[2],orien2lat[2];
FILE *f;
fopen_s(&f, "input.txt", "r");
if (f==NULL)
perror ("Error opening file");
else{
while(feof(f)== 0){
//Long of point 1
fscanf_s(f,"%d",&long1deg);
fscanf_s(f,"%d",&long1min);
fscanf_s(f,"%d",&long1sec);
fscanf_s(f,"%s",orien1lon);
// Lat of point 1
fscanf_s(f,"%d",&lat1deg);
fscanf_s(f,"%d",&lat1min);
fscanf_s(f,"%d",&lat1sec);
fscanf_s(f,"%s",orien1lat);
//Long of point 2
fscanf_s(f,"%d",&long2deg);
fscanf_s(f,"%d",&long2min);
fscanf_s(f,"%d",&long2sec);
fscanf_s(f,"%s",orien2lon);
//Lat of point 2
fscanf_s(f,"%d",&lat2deg);
fscanf_s(f,"%d",&lat2min);
fscanf_s(f,"%d",&lat2sec);
fscanf_s(f,"%s",orien2lat);
}
fclose(f);
}
But I always have this problem when I compile it: "Error opening file: No such file or directory".
Is there a specific location where I have to put my input.txt file? I suspect visual studio cannot find my text file. I opened the text file while compile my c++ file.
Thank you in advance.