为什么我的输出包含错误? [英] Why my output contain error?

查看:72
本文介绍了为什么我的输出包含错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//点击此处下载输出文件 https://drive.google.com/file / d / 0B5UNk0DIavhGWTRORGtWVUtZdlU / edit?usp = sharing [ ^ ]

//Click here to download output file https://drive.google.com/file/d/0B5UNk0DIavhGWTRORGtWVUtZdlU/edit?usp=sharing[^]

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

int main(){
    int ID_Student[10];
    int Average[10], sum;
    int score1[10], score2[10], score3[10];
    int j;
    char status[10][10];
    FILE *fptrInput;
    FILE *fptrOutPut;

    fptrInput = fopen("rawresult.dat","r");
    if(fptrInput==NULL){
        printf("Input File Can't opened!");
    }

    fptrOutPut = fopen("result.dat","w");
    if(fptrOutPut==NULL){
        printf("Output File Can't opened!");
    }
    for(j=0; j<=9; j++){
        fscanf(fptrInput,"%d%d%d%d", &ID_Student[j], &score1[j], &score2[j], &score3[j]);
        sum=score1[j]+score2[j]+score3[j];
        Average[j]=sum/3;
    }
    fprintf(fptrOutPut,"Detail Result of Each Student:\n");
    fprintf(fptrOutPut,"ID\tAverage\tStatus\n");

    for(j=0; j<=9; j++){
        if (Average[j]>=80 && Average[j]<=100)
            status[j]="Active";
        else
            status[j]="Dismiss";

        fprintf(fptrOutPut,"%d%d%s\n",&ID_Student[j], &Average[j], &status[j]);


    }

    fclose(fptrInput);
    fclose(fptrOutPut);
    return 0;

}



推荐答案

如果你意思是这不编译,为什么不呢?然后查看错误消息。

在这种情况下,表达式必须是可修改的左值并且将指向两行:

If you mean "this doesn't compile, why not?" then look at the error message.
Which in this case will be along the lines of "expression must be a modifiable lvalue" and which will point at the two lines:
status[j]="Active";
...
status[j]="Dismiss";



错误意味着您尝试分配的内容无效:您正在尝试将指向常量字符串的指针分配给指向普通字符串的指针 - 意味着你以后可以尝试改变常数,这会导致各种各样的恶意......



相反,试试这个:


What the error means is that what you are trying to assign isn't valid: you are trying to assign a pointer to a constant string to a pointer to a normal string - which means you could later try to alter a constant, which would lead to all sorts of nasties...

Instead, try this:

const char *status[10];






and

fprintf(fptrOutPut,"%d%d%s\n",&ID_Student[j], &Average[j], status[j]);



单独留下剩余的代码。



试试看看会发生什么!


Leave the rest of your code alone.

Try that and see what happens!


这篇关于为什么我的输出包含错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆