I have a file with a lot of lines like this:
1:458:187:131
1:1124:384:63
1:2300:514:31
2:95:111:12
...
In each while of reading I use a function to use those values so that in next iteration it can be stored in the same variable.
and then I have other with strings
6:City1:46:795:825:17134:8398:616:323:8791:5873
7:City near London:507:1032
8:NY:2595:64:193:684:1258:341:1125:1956:5079
It's the same process as before. Any help?
void readst()
{
int nn1, nn2,nn3,nn4;
char str1[200], str2[200];
char str[200];
FILE *fp;
fp = fopen("file.txt", "r");
if(!fp) return 1; // bail out if file not found
while(fgets(str,sizeof(str),fp) != NULL)
{
// strip trailing '\n' if it exists
int len = strlen(str)-1;
if(str[len] == '\n')
str[len] = 0;
int n1, n2,n3,n4;
char str1[200], str2[200];
sscanf(str,"%d:%d:%d:%d",&nn1,&nn2,&nn3,&nn4);
printf("%d\n%d\n%d\n%d\n",nn1,nn2,nn3,nn4);
printf("\n%s", str);
}
fclose(fp);
}