Thread: no ressult after compile and run?

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    2

    no ressult after compile and run?

    Hi everyone,
    im new here and ive got this code. No error message but i cant get my ressult after compile and run. System pause etc just show the message
    Syntax: programfile inputfile at the end.
    What i need to do so i can wright in the console year and average exam notes?
    thx for any help and sry for my english


    [tag]
    Code:
    
    
    Code:
    #include <stdio.h> #include <conio.h> 
    struct foitrec { 
    char fname[15]; 
    char lname[20]; 
    int year; 
    char exam; 
    int snote; 
    }; 
    
    
    void main(int argc, char *argv[]) { 
        
    FILE *fptr; 
    struct foitrec ftt; 
    float aver; 
    int count; 
    if(argc==2) { 
    if(fptr=fopen(argv[1],"r")) { 
    aver=0.0; 
    count=0; 
    while(fscanf(fptr,"%s %s %d %c %d",ftt.fname,ftt.lname,&ftt.year,&ftt.exam,&ftt.snote)!=EOF) 
    
    
    if(ftt.exam=='A' && ftt.year==1995) { 
                  
                     
    aver+=ftt.snote; 
    ++count; 
    } 
    aver/=count; 
    
    
    printf("Average=%f\n",aver); 
    
    
    } else 
    printf("Can't open file %s\n",argv[1]); 
    
    
    } else 
    printf("Syntax: programfile inputfile\n"); 
    
    
    
    
    }
    [/tag]

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Welcome.Your code does not insert the body of the if you want..(line 30-35),because this conditions are true
    Code:
    if(ftt.exam=='A' && ftt.year==1995)
    So this has to do with the data or/and with how you wrote the code(the conditions,where you did put the printf etc)

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    You have to call your program with a specific filename as a parameter.
    If you're using a command shell, try
    Code:
    program filename.dat

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    The following snippet is not quite correct:
    Code:
    while(fscanf(fptr,"%s %s %d %c %d",ftt.fname,ftt.lname,&ftt.year,&ftt.exam,&ftt.snote)!=EOF)
    The fscanf() function only returns EOF if a failure ocurrs reading the first item. What happens if it reads the first item correctly but fails to properly read the second?

    Since you are trying to read 5 items you may want to insure that the function does indeed read all 5 items. This function also returns the number of items successfully read if it reads any data. So I actually recommend that you replace the EOF with the number of format specifiers, in this case 5.

    Jim

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    2
    thank you guys for your replys,im working on it and ill post the right code in a few hours/days

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 06:00 AM
  2. Replies: 3
    Last Post: 03-07-2003, 09:06 PM
  3. Please help with compile for gcc
    By nevermind in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2002, 07:57 PM
  4. Won't compile, can YOU compile it on your compiler?
    By incognito in forum C++ Programming
    Replies: 12
    Last Post: 03-10-2002, 12:00 PM