-3
我有一个文本文件中的数据采用以下格式从文本文件中读取值?
WA5362288SeaTac city 25496 10176 434224 9.964121 0.167655 47.441406-122.293077
WA5363000Seattle city 563374 270524 151956998 83.872647 58.670927 47.626353-122.333144
现在我试图从上述数据中的特定值(已取得了一些填充空格去掉),例如
WA SeaTAC 47.441406 -122.293077
我不确定如何让C来自特定的列值,而通过一个文本文件流媒体
FILE *fp;
fp = fopen("places.txt", "r");
if(fp == NULL){
fprintf(stderr, "Can't open the file");
exit(1);
}
while(!feof(fp)){
//extract values from specific column
//fscanf()
}
这是有据可查的文件,并且在SO和整个网络上都有无数的答案。有什么具体的问题吗? –
第1步:阅读['while(!feof(file))'总是错误]并修复您的控制循环。第2步:使用['fgets()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fgets.html)或POSIX函数['getline()'](http://pubs.opengroup .org/onlinepubs/9699919799/functions/getline.html) 来读取行,然后可能使用['sscanf()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sscanf.html)解析线条。 –
请更具体。您的数据提取令人困惑。你是否只查找没有数字的第一列,最后两列? – texasbruce