小编oze*_*ech的帖子

C,从文件读入结构

几天来我一直在努力奋斗,我无法弄清楚为什么它不起作用.

我正在尝试从文件中读取带有这样的数字的数字:

0 2012 1 1 2000.000000
0 2012 1 1 3000.000000
1 2012 1 1 4500.000000
Run Code Online (Sandbox Code Playgroud)

我的结构:

struct element{

        int id;
        int sign;
        int year;
        int month;
        double amount;

        struct element *next;


};

struct queue{
    struct element *head;
    struct element *tail;
    struct element *head2; 
    struct element *temp;  
    struct element *temph; 

    int size;
};
Run Code Online (Sandbox Code Playgroud)

(head2,temp和temph用于排序结构)

并从文件中读取:

void read_str(struct queue *queue){

    FILE *reads;

    char filename[40];
    int temp;

    printf("Type in name of the file\n");
    scanf("%s",&filename);
    reads=fopen(filename, "r");
    if (reads==NULL) {
        perror("Error");
        return …
Run Code Online (Sandbox Code Playgroud)

c structure file

4
推荐指数
1
解决办法
6万
查看次数

标签 统计

c ×1

file ×1

structure ×1