Click here to Skip to main content
15,917,588 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
//Click here to download output file https://drive.google.com/file/d/0B5UNk0DIavhGWTRORGtWVUtZdlU/edit?usp=sharing[^]
C#
#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;

}

Posted
Updated 23-Dec-13 4:30am
v3
Comments
thatraja 23-Dec-13 10:26am    
what's the error? Always include those details in your question for quick response.
JaironLanda 23-Dec-13 10:32am    
please download output file..
thatraja 23-Dec-13 10:34am    
No one is going to download the file. Besides some of us(including me[But I know how to write "hello world"]) don't know C.

Asked you for error message.
JaironLanda 23-Dec-13 10:40am    
so you have solution?
thatraja 23-Dec-13 10:43am    
:'( Asked you for error message twice. I give up :'(

1 solution

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:
C#
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:
C++
const char *status[10];

and
C++
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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900