赋值在没有强制转换的情况下从指针生成整数(C中的单链表方法)

时间:2017-09-30 17:00:22

标签: c list

我使用单链表结构代替数组来计算我程序中通过CSV文件输入的成绩的平均值。但是,在调用应该起作用的方法时,我无法分配它们返回的内容。我在我的主要方法中使用以下方法:

int main(int argc, char **argv){
    int i = 0;
    FILE *inf;
    struct List list = SLL_new();
    int c = 0;

    for(int i = 1; i < argc; i++){
        inf = fopen(argv[i], "r");
        int studentID = 0;
        int grade = 0;
        if(inf == NULL){
            printf("No such file found/n");
            exit(1);
        }
        while(1) {
            int ret = fscanf(inf, "%d,%d", &studentID, &grade);
            if(ret == 2){
                SLL_insert(&list, studentID, grade);
                c++;
            }
            else if(ret == EOF){
                fclose(inf);
                break;
            }
            else {
                printf("No match.\n");
            }
        }
    }
    SLL_print(&list);
    FILE *outf;
    outf = fopen("finalgrade.csv", "w");
    if (outf == NULL)
    {
        printf("Error opening file!\n");
        exit(1);
    }
    while(SLL_empty == 0){
        int sum = 0;
        int id = SLL_getID;
        sum+=SLL_pop;
        sum+=SLL_pop;
        sum+=SLL_pop;
        float avg = sum/3;
        fprintf(outf, "%d,%f\n", id, avg);
    }
    fclose(outf);
}

主:

amazingCalculator.c: In function 'main':
amazingCalculator.c:170:12: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
   int id = SLL_getID;
            ^
amazingCalculator.c:171:6: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
   sum+=SLL_pop;
      ^
amazingCalculator.c:172:6: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
   sum+=SLL_pop;
      ^
amazingCalculator.c:173:6: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
   sum+=SLL_pop;
      ^
          ^

编译错误:

{{1}}

我不确定问题是什么,我相当肯定这些方法是正确的,因为我已经在之前对它们进行了测试。我不是在我的while循环中分配它们正确返回的内容吗?我是C和指针概念的新手。

0 个答案:

没有答案