c - <= token 之前的预期表达式

标签 c arrays linux compiler-construction

当我在 linux 中编译时出现错误:

project9v2.c: In function `main`:
project9v2.c:34:33: error: expected expression before `<=` token
project9v2.c:38:33: error: expected expression before `<=` token
project9v2.c:42:33: error: expected expression before `<=` token
project9v2.c:46:33: error: expected expression before `<=` token

它扫描文件 a.txt 并应该输出到 b.txta.txt的内容是:

97 85 70 84 33 100 283 53 81 69 89 73 65 86 77 556 -1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *inFile, *outFile;
    int current;
    int sum = 0, b, i;
    int A=0, B=0, C=0, D=0, F=0;
    int theGrades[100];


    inFile = fopen("a.txt", "r");
    outFile = fopen("b.txt", "w");

    if (inFile != NULL) 
    {
        b = fscanf(inFile, "%d", &current); 
    }

    while(b != -1)
    {
        theGrades[sum] = current;
        sum++;
        b = fscanf(inFile, "%d", &current);
    }

    for(i=0; i<sum; i++)
    {
        if (theGrades[i] <0)
        {
            break;
        }
        else if (theGrades[i] >=90 && <=100)
        {
            A++;
        }
        else if (theGrades[i] >=80 && <=89)
        {
            B++;
        }
        else if (theGrades[i] >=70 && <=79)
        {
            C++;
        }
        else if (theGrades[i] >=60 && <=69)
        {
            D++;
        }
        else  
        {
            F++;
        }
    }
    fprintf(outFile, "The total number of grades is:" , sum);
    fprintf(outFile, "Number of A’s = %d\n" ,A);
    fprintf(outFile, "Number of B’s = %d\n" ,B);
    fprintf(outFile, "Number of C’s = %d\n" ,C);
    fprintf(outFile, "Number of D’s = %d\n" ,D);
    fprintf(outFile, "Number of F’s = %d\n" ,F);

    fclose(inFile);
    fclose(outFile);
    }

最佳答案

按照c语法,你应该像下面这样修改它。 :) 比较运算符应该在两个变量或数字之间使用。

    else if (theGrades[i] >=90 && theGrades[i]<=100)
    {
        A++;
    }
    else if (theGrades[i] >=80 && theGrades[i]<=89)
    {
        B++;
    }
    else if (theGrades[i] >=70 && theGrades[i]<=79)
    {
        C++;
    }
    else if (theGrades[i] >=60 && theGrades[i]<=69)

关于c - <= token 之前的预期表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124729/

相关文章:

c - 从简单的 C 程序获取核心转储

JavaScript 遍历数组以检查数值

linux - 将数据从内核驱动程序复制到用户空间驱动程序的最佳方法

linux - 编译到内核中的驱动程序的 init 函数调用

c - 在 C 中将数组存储为链表

c - #if 将 undefined symbol 常量假定为 0 是标准的吗?

javascript - 如何定位名称等于变量值的数组?

linux - 将 X11 窗口保持在另一个窗口之上

c++ - 使用 printf ("text %d", number) 类型格式给变量赋值

java - 如何仅打印数组中具有重复字符的单词?