>>>>>line 15: remove the quotes around filename.
i removed quotes at line 15 and


>>>>line 74: you close the file at the end of the first loop iteration. Move that line down after the }
closed file after first for loop

And the results were ???

i think i have to sleep now because i am living in someone else house now a days
but tomorrow i will be here at same time
and at morning time i will check for updates
PLEASE RUN THIS PROGRAM ON UR COMPUTER AND SEE WHAT EXCEPTIONS COME THERE
I AM USING BLOODSHED DEV C++ 4.96 VERSION
THANKS ALOT I REALLY APPREICAITE YOU PEOPLE GIVING ME UR IMPORTANT TIME

Oh sorry
results are same !

It is writing the data to file but now not reading properly.
i just saved a file and saw all data is written there
but results are same .

#include<stdio.h>
[LIST=1]
#include<string.h>
#include<conio.h>
#pragma warning(disable: 4996)
 
float avg(float x);
main()
{
    FILE *fp;
    int k,students=10,subjects=4,i,j,id_number,fail;
    float marks[100],total=0,average;
    char name[30],course_enrolled[30],filename[255],date_of_birth[30];
    printf("filename\n"); 
    scanf("%s",filename);
    fp=fopen(filename,"w");
    for(i=1;i<=2;i++)
    {     
        printf("Enter Name of Student\n");
        fscanf(stdin,"%s",name);
        fprintf(fp,"%s\n",name);
        
        printf("Enter Course In Which Student Is Enrolled\n"); 
        fscanf(stdin,"%s",course_enrolled);
        fprintf(fp,"%s\n",course_enrolled);
        
        printf("Enter Date Of Birth\n");
        fscanf(stdin,"%s",date_of_birth);
        fprintf(fp," %s\n",date_of_birth);
        
        printf("Enter ID Number\n");
        fscanf(stdin,"%d",&id_number);
        fprintf(fp," %d\n",id_number);
        
        for(j=1;j<=4;j++)
        {
            printf("Enter Marks for Subject\n");
            scanf("%f",&marks[j]);
            total=total+marks[j];
            if(marks[j]<50)
                fail=fail+1;
            else
                continue;
        } 
        average=avg(total);
        total=0.0;
        printf("AVERAGE=%2f\n",average);
        fprintf(fp," %2f\n",average);
        if(average>=70)
            printf("Grade A\n");
        else if(average>=60&&average<70)
            printf("Grade B\n");
        else if(average>=50&&average<60)
            printf("Grade C\n");
        else if(average>=45&&average<50) 
            printf("Grade D\n");
        else if(average>=40&&average<45)
            printf("Grade E\n");
        else if(average<40)
            printf("Fail\n");
        else 
             continue;
        
        if(fail>=2)
        printf("Student is failed and cann;t promote\n");
        else
        continue;
        fail=0;
    }
    fclose(fp); 
    printf("Input filename"); 
    scanf("%s",filename);
    fp=fopen(filename,"r");
    for(k=1;k<=2;k++)
    {
     fscanf(fp,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s   AVERAGE= %2f\n",name,course_enrolled,&id_number,date_of_birth,average);
     fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s    AVERAGE= %2f\n",name,course_enrolled,id_number,date_of_birth,average);
    }
    fclose(fp);
    getch();
}
float avg(float x)
{
      float a=0.0;
      a=(x/400)*100;
      return (a);
}
[/LIST]

?????

delete lines 70 and 71 because the program already knows the filename from lines 13 and 14. No point in asking for the filename again.

line 75: fscanf() is mal-formed. Here is correction

while(fscanf(fp,"%s%s%s%d%f",
        name,
        course_enrolled,
        date_of_birth,
        &id_number,
        &average) > 0)
    {
        fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,average);
    }

I believe this will work better. Note that you were writing out the variables in a slightly different order than you were fscanf'ing them back in, and the failing message shouldn't go into the data file, because you have no way of handling it when the data is read back in.

Instead, just add an if statement to your program after the data is read back in from the file, and then print the "student has failed and can't promote" message, onto the screen.

#include<stdio.h>
#include<string.h>
#include<conio.h>
#pragma warning(disable: 4996)
 
float avg(float x);
int main()
{
    FILE *fp;
    int k,students=10,subjects=4,i,j,id_number,fail;
    float marks[100],total=0,average;
    char name[30],course_enrolled[30],filename[10],date_of_birth[30];
       //printf("filename\n"); 
       //scanf("%s",filename);
    printf("\n\n\n\n");

    fp=fopen("filename","w");
    for(i=1;i<=10;i++)
    {     
        printf("Enter Name of Student\n");
        fscanf(stdin,"%s",name);
        fprintf(fp,"%s\n",name);
        
        printf("Enter Course In Which Student Is Enrolled\n"); 
        fscanf(stdin,"%s",course_enrolled);
        fprintf(fp,"%s\n",course_enrolled);
        
        printf("Enter Date Of Birth\n");
        fscanf(stdin,"%s",date_of_birth);
        fprintf(fp," %s\n",date_of_birth);

        printf("Enter ID Number\n");
        fscanf(stdin,"%d",&id_number);
        fprintf(fp," %d\n",id_number);

        for(j=0;j<4;j++)
        {
            printf("Enter Marks for Subject\n");
            scanf("%f",&marks[j]);
            total=total+marks[j];
            if(marks[j]<50)
                fail=fail+1;
//            else
//                continue;
        } 
        average=avg(total);
        total=0.0;
        printf("AVERAGE=%f\n",average);
        fprintf(fp," %f\n",average);
        if(average>=70)
            printf("Grade A\n");
        else if(average>=60&&average<70)
            printf("Grade B\n");
        else if(average>=50&&average<60)
            printf("Grade C\n");
        else if(average>=45&&average<50) 
            printf("Grade D\n");
        else if(average>=40&&average<45)
            printf("Grade E\n");
        else if(average<40)
            printf("Fail\n");
//        else 
//             continue;
        
        
        
        
        if(fail>=2)
           { 
                   printf("Student is failed and can't promote\n");
                 //fprintf(fp,"Student is failed and can't promote\n");
           }        
//        else
//            continue;
        fail=0;

    }
    fclose(fp); 
    fp=fopen("filename","r");
    for(k=1;k<=10;k++)
    {
           //printf("Input filename"); 
           //scanf("%s",filename);
        //fscanf(fp,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,&id_number,date_of_birth,average);
        fscanf(fp,"%s %s %s %d %f",name,course_enrolled,date_of_birth, &id_number,&average);
        fprintf(stdout,"NAME= %s\tCOURSE= %s\t ID= %d\t DOB= %s\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,average);

       if(average < 40)
          printf("\n*This student has failed and can't promote*\n");
    }
    fclose(fp);
    getch();
    return 0;
}
float avg(float x)
{
      float a=0.0;
      a=(x/400)*100;
      return (a);
}

Thanks alot for solving my problem but in future i will contact you to get more knowledge from you!
thanks alot everyone/
i still have questions about my program (so that i clear my concepts) but i will ask them at morning . bye
again million thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.