Thread: Parse Error - Anyone Help?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    25

    Parse Error - Anyone Help?

    Hi guys,

    I have a parse error, it maybe syntax or just some code is not right. Anybody help?

    Here is the code:

    [tag]

    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    struct student
    
    {
    char* list[50];
    char* number[10];
    char* name[20];
    char* grade[20];
    };
    
    struct student list [10]={
    {"000001", "Bloomer", "B"},
    {"000002", "Brown", "A"},
    {"000003", "Carter", "A"},
    {"000004", "James", "B"},
    };
    
    char GetOption()
    {char option = 'I';
    while(option == 'I'){
    {printf("\n");
    printf(" Please choose one of the options: \n \t\t\t [U]pdate  [P]rint [S]earch  [E]xit \n");
    scanf("%c", &option);
    switch (toupper(option))
    {
    case 'U' :
    case 'P' :
    case 'S' :
    case 'E' :
    break;
    default:
    option = 'I';
    break;
    }
    }
    
    void searchstudent()
    { int count;
    char num,f;
    printf("Enter the student number you wish to search for : \n");
    scanf("%c", &num);
    f='b';
    for (count=0; count<10; count++)
    {
    if(num==struct student list [count])
    {
    print("%c was found at location %d", num, count);
    count=10;
    f='a'
    }
    }
    if (f=='b') printf("%c was not found", id);
    }
    [/tag]



    'Parse error before struct'


    This is not the whole code but just trying to break the code down.

    Thanks

  2. #2
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    There are 2 closing brackets missing ! Indent your code
    Code:
    char GetOption()
    {
    	char option = 'I';
    	while(option == 'I')
    	{
    		{
    			printf("\n");
    			printf(" Please choose one of the options: \n \t\t\t [u]pdate  [P]rint
    					[S]earch  [E]xit				
    					\n");
    			scanf("%c", &option);
    			switch (toupper(option))
    			{
    				case 'U' :
    				case 'P' :
    				case 'S' :
    				case 'E' :
    					break;
    				default:
    					option = 'I';
    					break;
    			}
    		}
    Last edited by AnishaKaul; 04-15-2010 at 02:27 AM.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    Thanks, I can now see that and have amended, however still same problem

    Seems to be in this area of code / function:

    [tag]
    Code:
    void searchstudent()
    { int count;
    char num,f;
    printf("Enter the student number you wish to search for : \n");
    scanf("%c", &num);
    f='b';
    for (count=0; count<10; count++)
    {
    if(num==struct student list [count])
    {
    print("%c was found at location %d", num, count);
    count=10;
    f='a'
    }
    }
    if (f=='b') printf("%c was not found", id);
    }
    [/tag]

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    Thanks, I can now see that and have amended, however still same problem

    Seems to be in this area of code / function:

    [tag]
    Code:
    void searchstudent()
    { int count;
    char num,f;
    printf("Enter the student number you wish to search for : \n");
    scanf("%c", &num);
    f='b';
    for (count=0; count<10; count++)
    {
    if(num==struct student list [count])
    {
    print("%c was found at location %d", num, count);
    count=10;
    f='a'
    }
    }
    if (f=='b') printf("%c was not found", id);
    }
    [/tag]

  5. #5
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    Code:
    void searchstudent()
    { int count;
    char num,f;
    printf("Enter the student number you wish to search for : \n");
    scanf("%c", &num);
    f='b';
    for (count=0; count<10; count++)
    {
    if(num==struct student list [count])
    {
    print("%c was found at location %d", num, count);
    count=10;
    f='a'
    }
    }
    if (f=='b') printf("%c was not found", id);
    }
    ; is missing here !

    You could have done this bracketing and semi colon exercise yourself too !

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    Parse error before, before STRUCT:

    line 52 if(num== struct student list [count])


    I am doing something wrong in this line compared to the original code:

    the f='a' is after this bit of code..



    'parse error before struct, line 52'

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    Parse error before, before STRUCT:

    line 52 if(num== struct student list [count])


    I am doing something wrong in this line compared to the original code:

    the f='a' is after this bit of code..



    'parse error before struct, line 52'

  8. #8
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Whenever you reference the structure after you have declared it, you do not need to write 'struct student', just 'list' (and the element number).

    Also, you're attempting to compare a character to a structure, this cannot be done with relational operators like ==. If you want to compare it to a member of the structure you have to use the dot operator.

    This mistake isn't really obvious even with good indentation but as AnishaKaul has stated, indentation is very helpful and pretty much a requirement if you wish for other people to read your code. Next time you post, please indent your code.

  9. #9
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    OK, here is my problem stripped down...

    If anyone could help then it would be great..

    These are my structures:


    [tag]
    Code:
    
    struct student
    {
    
    char* number[10];
    char* name[20];
    char* grade[20];
    };
    
    struct student records[4]={
    {"00001", "Bloomer", "B"},
    {"00002", "Smith", "A"},
    {"00003", "James", "B"},
    {"00004", "Doug", "C"},
    };
    [/tag]

    That bit looks OK, and you can see the labels that I have used:


    My function when I am trying to call the labels are for example, when trying to load them:


    [tag]
    Code:
    void Loadstudents (struct student records[])
    {
    FILE *fp=fopen("records.txt", "r");
    }
    [/tag]



    The void 'Loadstudents (struct student records[])' part, I am not sure about.

    Thanks

  10. #10
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    OK, here is my problem stripped down...

    If anyone could help then it would be great..

    These are my structures:


    [tag]
    Code:
    
    struct student
    {
    
    char* number[10];
    char* name[20];
    char* grade[20];
    };
    
    struct student records[4]={
    {"00001", "Bloomer", "B"},
    {"00002", "Smith", "A"},
    {"00003", "James", "B"},
    {"00004", "Doug", "C"},
    };
    [/tag]

    That bit looks OK, and you can see the labels that I have used:


    My function when I am trying to call the labels are for example, when trying to load them:


    [tag]
    Code:
    void Loadstudents (struct student records[])
    {
    FILE *fp=fopen("records.txt", "r");
    }
    [/tag]



    The void 'Loadstudents (struct student records[])' part, I am not sure about.

    Thanks

  11. #11
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    OK thanks dead planet, will do..

    Just reading your post, thanks..

  12. #12
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    OK thanks dead planet, will do..

    Just reading your post, thanks..

  13. #13
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    boom71uk

    Kindly check why all your posts get posted twice ?

  14. #14
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    OK not sure why it is reposting my messages, checked all settings and seem fine?

    Anyway I have worked quite a bit on my code overnight and have got 90% of it working, just wanted to ask some help on data being stored in a file and then retrieved.

    These are my two functions for adding a record, and listing records:


    [tag]
    Code:
     void Add(void){
    char opt;
    fp=fopen("Records2.txt","a");
    printf("\nAdd Record");
    printf("\nStudent Name:"); scanf(" "); gets(record.Name);
    printf("\nStudent Number:");scanf(" "); gets(record.Number);
    printf("\nStudent Grade:");scanf(" "); gets(record.Grade);
    fprintf(fp,"%s %s %s ",record.Name,record.Number,record.Grade);
    printf("Press any key to go to main menu..."); 
    getch();
    fclose(fp);
    }
    [tag]


    [tag]
    Code:
    void List(void){
    int count=0,i, x=0;
    fp=fopen("Records2.txt","r");
    printf("Name   Number   Grade\n\n");
    for(i=1;i<1;i++){ ;puts("Í");}
    while(fscanf(fp,"%s %s %s",&record.Name,&record.Number,&record.Grade)!=EOF){
    if(count!=0&&count%5==0){ printf("Press any key to continue..."); getch(); x=0;
    for(i=10;i<=24;i++);}
    }
    printf("%s   %s    %s",record.Name,record.Number,record.Grade);
    x++;
    count++;
    printf("\nPress any key to go to main menu...");
    getch();
    fclose(fp);
    }
    [/tag]


    These all compile and work to a degree but when I run my program, only the last record is shown on the screen and not all the records stored in the text file. Any hints or help on this?

    I do not think I am a million miles away..

    Thanks In Advance!

  15. #15
    Registered User
    Join Date
    Apr 2010
    Posts
    25
    OK not sure why it is reposting my messages, checked all settings and seem fine?

    Anyway I have worked quite a bit on my code overnight and have got 90% of it working, just wanted to ask some help on data being stored in a file and then retrieved.

    These are my two functions for adding a record, and listing records:


    [tag]
    Code:
     void Add(void){
    char opt;
    fp=fopen("Records2.txt","a");
    printf("\nAdd Record");
    printf("\nStudent Name:"); scanf(" "); gets(record.Name);
    printf("\nStudent Number:");scanf(" "); gets(record.Number);
    printf("\nStudent Grade:");scanf(" "); gets(record.Grade);
    fprintf(fp,"%s %s %s ",record.Name,record.Number,record.Grade);
    printf("Press any key to go to main menu..."); 
    getch();
    fclose(fp);
    }
    [tag]


    [tag]
    Code:
    void List(void){
    int count=0,i, x=0;
    fp=fopen("Records2.txt","r");
    printf("Name   Number   Grade\n\n");
    for(i=1;i<1;i++){ ;puts("Í");}
    while(fscanf(fp,"%s %s %s",&record.Name,&record.Number,&record.Grade)!=EOF){
    if(count!=0&&count%5==0){ printf("Press any key to continue..."); getch(); x=0;
    for(i=10;i<=24;i++);}
    }
    printf("%s   %s    %s",record.Name,record.Number,record.Grade);
    x++;
    count++;
    printf("\nPress any key to go to main menu...");
    getch();
    fclose(fp);
    }
    [/tag]


    These all compile and work to a degree but when I run my program, only the last record is shown on the screen and not all the records stored in the text file. Any hints or help on this?

    I do not think I am a million miles away..

    Thanks In Advance!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM