[英]Reading a text file line by line into a structure in c
I am kind of new to c programming but I want to create ac function that can read contents of a text file line by line separated by the tab delimiter(\\t) and store them into a data structure, then after clear the file but have still failed. 我是C编程的新手,但是我想创建一个ac函数,该函数可以逐行读取由制表符定界符(\\ t)分隔的文本文件的内容,并将其存储到数据结构中,然后在清除文件后但是仍然失败。 My code is
我的代码是
struct Busy_list{
int client_socket;
char JOB[1024];
int characters;
int No_jobs;
int IsReplace;
int Priority;
};
char** PriorityEvaluator(int client_socket){
struct Busy_list Array;
FILE *Ufptr;
Ufptr = fopen("Unsorted_busy_list.txt","r+");
for(int i;!EOF;i++){
fscanf(Ufptr, "%d\t%s\t%d\t%d\t%d\n",&Array.client_socket,&Array.JOB,&Array.characters,&Array.No_jobs,&Array.IsReplace);
}
fclose(Ufptr);
}
My Unsorted_busy_list file contains 我的Unsorted_busy_list文件包含
/*
4 double fish 4 1 0
5 double praise 6 2 0
5 replace peter 2-o,4-o 5 2 1
*/
Try to replace your for loop with a while loop like this: 尝试用while循环替换for循环,如下所示:
while((fscanf(Ufptr, "%d\t%s\t%d\t%d\t%d\n",&Arguments...)) != EOF){
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.