HELP plse

This is a discussion on HELP plse within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to make a grade management program and I have everything but my sort function is not ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    40

    HELP plse

    Hi, I am trying to make a grade management program and I have everything but my sort function is not working and I am getting a parse error at the end of input.. Could someone please help... Thanks


    Code:
       #include <stdio.h>
       #include <string.h>
       #include <stdlib.h>
    
       void readfile(char name, int grade1,int grade2,int grade3);
       int meangrade(int grade1,int grade2,int grade3);
       void display(char name, int grade1,int grade2,int grade3);
       int qsort(char name, int grade1, int grade2, int grade3, int
    meangrade);
         struct grades
        {
         int grade1;
         int grade2;
         int grade3;
        };
    
          struct grades name[30], g1, g2, g3,*gptr;
    
          FILE *infile;
          FILE *outfile;
    
       int main(int argc, char **argv) {
        {
         char filename;
         int choice, exam;
         FILE *infile = fopen("grade.txt", "r");
         FILE *outfile = fopen("grades.txt","w");
    
        printf ("Please enter the filename needed:  \n");
        scanf("%c", &filename);
        int main(int argc, char **argv) {
        {
         char filename;
         int choice, exam;
         FILE *infile = fopen("grade.txt", "r");
         FILE *outfile = fopen("grades.txt","w");
    
        printf ("Please enter the filename needed:  \n");
        scanf("%c", &filename);
        printf("Please enter 1 for a specific exam to be displayed or 0 to exit. \n$
        scanf("%d", choice);
             if (choice == 0)
                 display;
             else
                printf("Goodbye....\n");
    
            fclose(infile);
            fclose(outfile);
    
           return 0;
    }
       void readfile(char filename,char name[30],int grade1,int grade2,int grade3){
          fscanf(infile,"%c %d%d%d", name[30], &grade1, &grade2,&grade3);
      }
       int meangrade(int grade1,int grade2,int grade3,int meangrade){
           meangrade = (grade1 +grade2 +grade3)/3;
           return meangrade;
         }
        }
       void readfile(char filename,char name[30],int grade1,int grade2,int grade3){
          fscanf(infile,"%c %d%d%d", name[30], &grade1, &grade2,&grade3);
      }
       int meangrade(int grade1,int grade2,int grade3,int meangrade){
           meangrade = (grade1 +grade2 +grade3)/3;
           return meangrade;
         }
    
       void display(char filename,char name[30], int grade1,int grade2,int grade3){
               int exam;
               printf("Which exam number would you like to see?    ");
               scanf("%d", &exam);
                 if (exam > 3) {
                     printf("Please enter a valid exam number:  ");
                     scanf("%d", &exam);
                 else
                    fprintf(infile,"%s%d%d%d", name[30], &grade1,&grade2, &grade3);
    
           int exam;
               printf("Which exam number would you like to see?    ");
               scanf("%d", &exam);
                 if (exam > 3) {
                     printf("Please enter a valid exam number:  ");
                     scanf("%d", &exam);
                 else
                    fprintf(infile,"%s%d%d%d", name[30], &grade1,&grade2, &grade3);
             }
       }
    
            int qsort(char name[30], int grade1,int grade2,int grade3, int meangrad$
               int j, max;
               for( j = 0; j < 100; ++j) {
                  if (name[j].grade1 > name[j].grade2)
                       max = name[j].grade1;
                  else
                       max = name[j].grade2;
                  if (name[j].grade3 > max)
    
                       max = name[j].grade3;
               return qsort;
            }
       }

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Have you looked at your post? I am not sure what you did but it is all messed up. Why don't you try cleaning it up a bit and then maybe someone will look at it.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    Hope this is better:

    Code:
     #include <stdio.h>
       #include <string.h>
       #include <stdlib.h>
    
       void readfile(char name, int grade1,int grade2,int grade3);
       int meangrade(int grade1,int grade2,int grade3);
       void display(char name, int grade1,int grade2,int grade3);
       int qsort(char name, int grade1, int grade2, int grade3, int meangrade);
         struct grades
        {
         int grade1;
         int grade2;
         int grade3;
        };
    
        struct grades name[30], g1, g2, g3,*gptr;
    
         FILE *infile;
         FILE *outfile;
     
        int main(int argc, char **argv) {
        {
         char filename;
         int choice, exam;
         FILE *infile = fopen("grade.txt", "r");
         FILE *outfile = fopen("grades.txt","w");
    
        printf ("Please enter the filename needed:  \n");
        scanf("%c", &filename);
        int main(int argc, char **argv) {
        {
        char filename;
        int choice, exam;
        
        FILE *infile = fopen("grade.txt", "r");
        FILE *outfile = fopen("grades.txt","w");
    
        printf ("Please enter the filename needed:  \n");
        scanf("%c", &filename);
        printf("Please enter 1 for a specific exam to be displayed or 0 to exit. \n$
        scanf("%d", choice);
             if (choice == 0)
                 display;
             else
                printf("Goodbye....\n");
    
         fclose(infile);
         fclose(outfile);
    
           return 0;
    }
         void readfile(char filename,char name[30],int grade1,int grade2,int grade3){
          fscanf(infile,"%c %d%d%d", name[30], &grade1, &grade2,&grade3);
      }
         int meangrade(int grade1,int grade2,int grade3,int meangrade){
         meangrade = (grade1 +grade2 +grade3)/3;
        return meangrade;
         }
        }
         void readfile(char filename,char name[30],int grade1,int grade2,int grade3){
         fscanf(infile,"%c %d%d%d", name[30], &grade1, &grade2,&grade3);
      }
         int meangrade(int grade1,int grade2,int grade3,int meangrade){
         meangrade = (grade1 +grade2 +grade3)/3;
         return meangrade;
         }
    
         void display(char filename,char name[30], int grade1,int grade2,int grade3){
         int exam;
         printf("Which exam number would you like to see?    ");
         scanf("%d", &exam);
           if (exam > 3) {
           printf("Please enter a valid exam number:  ");
           scanf("%d", &exam);
           else
           fprintf(infile,"%s%d%d%d", name[30], &grade1,&grade2, &grade3);
    
           int exam;
           printf("Which exam number would you like to see?    ");
           scanf("%d", &exam);
                 if (exam > 3) {
                     printf("Please enter a valid exam number:  ");
                     scanf("%d", &exam);
                 else
                    fprintf(infile,"%s%d%d%d", name[30], &grade1,&grade2, &grade3);
             }
       }
    
            int qsort(char name[30], int grade1,int grade2,int grade3, int meangrad$
               int j, max;
               for( j = 0; j < 100; ++j) {
                  if (name[j].grade1 > name[j].grade2)
                       max = name[j].grade1;
                  else
                       max = name[j].grade2;
                  if (name[j].grade3 > max)
    
                       max = name[j].grade3;
               return qsort;
            }
       }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Your indenting is horrible.

    Code:
    int qsort(char name[30], int grade1,int grade2,int grade3, int meangrad$
    /* missing something? */
        int j, max;
        for( j = 0; j < 100; ++j) {
            if (name[j].grade1 > name[j].grade2)
                max = name[j].grade1;
            else
                max = name[j].grade2;
            if (name[j].grade3 > max)
                max = name[j].grade3;
            return qsort;
        }
    }
    See what good indenting does for you? I've hilighted the problems. You should be able to fix it from there.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    still having issues with the sort function.

  6. #6
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    my sort function is not working
    still having issues with the sort function.
    Can you be a little more specific?
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    I am getting the following errors when I compile my code above and I can't figure out what is the problem.

    Code:
    grades.c:18: conflicting types for `qsort'
    /local/gnu/lib/gcc-lib/sparc-sun-solaris2.8/3.0.4/include/iso/stdlib_iso.h:123: previous declaration of `qsort'
    grades.c: In function `display':
    grades.c:69: parse error before "else"
    grades.c: In function `qsort':
    grades.c:78: request for member `grade1' in something not a structure or union
    grades.c:78: request for member `grade2' in something not a structure or union
    grades.c:79: request for member `grade1' in something not a structure or union
    grades.c:81: request for member `grade2' in something not a structure or union
    grades.c:82: request for member `grade3' in something not a structure or union
    grades.c:83: request for member `grade3' in something not a structure or union
    grades.c: In function `main':
    grades.c:87: parse error at end of input

  8. #8
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Code:
    grades.c:78: request for member `grade1' in something not a structure or union
    grades.c:78: request for member `grade2' in something not a structure or union
    grades.c:79: request for member `grade1' in something not a structure or union
    grades.c:81: request for member `grade2' in something not a structure or union
    grades.c:82: request for member `grade3' in something not a structure or union
    grades.c:83: request for member `grade3' in something not a structure or union
    Have you looked at your function for your sort. Lets take a look:
    Code:
    int qsort(char name[30], int grade1,int grade2,int grade3, int meangrad$
    To me and your compiler that means you are passing an array of 30 characters, not your structure. Your definition would need to be like:

    Code:
    int qsort( struct grades name[30], int grade1,int grade2,int grade3, int meangrad$
    Code:
    grades.c: In function `display':
    grades.c:69: parse error before "else"
    Well lets look at display, hmm.
    Code:
    if (exam > 3) {
           printf("Please enter a valid exam number:  ");
           scanf("%d", &exam);
           }else
           fprintf(infile,"%s%d%d%d", name[30], &grade1,&grade2, &grade3);
    You are forgetting to close out your if statements. You have done this throughout that function. Try fixing those.
    Code:
    grades.c: In function `main':
    grades.c:87: parse error at end of input
    hmmm, lets look at the scanf....
    Code:
    scanf("%d", &choice);
    Last edited by andyhunter; 02-05-2005 at 10:16 PM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21