Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Need help... again

  • 18-03-2005 2:55pm
    #1
    Registered Users, Registered Users 2 Posts: 2,327 ✭✭✭


    Aight.. I keep getting this one error in my program, makes no sense to me whatsoever. I have a sneaking suspiscion it might be Visual Studio.NET throwing a hissy fit. I get an error c2059: syntax error 'type' in line 50, anyone know what that means? After 2 hours of poking around to fix it, it's driving me to tears.
    #include <stdio.h>
    
    typedef struct stud
    {
    	int id;
    	char name[30];
    	char subject[30];
    	char grade;
    }student;
    
    
    void prompt(void);
    void add(FILE **inp, FILE **outp);
    void edit(FILE **inp, FILE **outp);
    void read(FILE **inp);
    void grades(FILE **inp);
    
    void main()
    {
    	FILE *inp, *outp;
    	int option;
    	
    	do
    	{
    		prompt();
    		scanf("%d", &option);
    		if(option == 1)
    		{
    			add(&inp, &outp);
    		}
    		else if(option == 2)
    		{
    			edit(&inp, &outp);
    		}
    		else if(option == 3)
    		{
    			read(&inp);
    		}
    		else if(option == 4)
    		{
    			grades(&inp);
    	}while(option != 5);
    
    	
    }
    
    void prompt(void)
    {
    	printf("Please select the option you wish to take\n");
    	printf("1. Add new students to records\n");
    	printf("2. Edit current student records\n");
    	printf("3. Read the file\n");
    	printf("4. Produce a report indicating overall grade for 5 subjects per student\n");
    	printf("5. Quit this program\n");
    }
    
    void add(FILE **inp, FILE **outp)
    {	
    	
    	student thestudent;
    
    	*inp = fopen("students.txt", "r");
    	*outp = fopen("temp.txt", "w");
    
    	//copy the contents of student.txt to temp.txt
    	while((fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF))
    	{
    		fprintf(*outp, "%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	}
    
    	printf("Student ID:\n");
    	scanf("%d", thestudent.id);
    	printf("Name:\n");
    	scanf("%s", thestudent.name);
    	printf("Subject 1:\n");
    	scanf("%s",thestudent.subject);
    	printf("Grade:\n");
    	scanf("%c", thestudent.grade);
    
    	//insert at end of output file
    	fprintf(*outp, "%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	
    	fclose(*inp);
    	fclose(*outp);
    
    	remove("students.txt");
    	rename("temp.txt", "students.txt");
    }
    
    void edit(FILE **inp, FILE **outp)
    {
    	student thestudent;
    
    	int editID;
    	*inp = fopen("students.txt", "r");
    	*outp = fopen("temp.txt", "w");
    	printf("Enter student's ID\n");
    	scanf("%d", &editID);
    
    	while(fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF)
    	{
    		if(thestudent.id == editID)
    		{
    			printf("Student ID:\n");
    			scanf("%d", thestudent.id);
    			printf("Name:\n");
    			scanf("%s", thestudent.name);
    			printf("Subject 1:\n");
    			scanf("%s",thestudent.subject);
    			printf("Grade 1:\n");
    			scanf("%c", thestudent.grade);
    
    		}
    
    
    		fprintf(*outp, "%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	}
    
    	fclose(*inp);
    	fclose(*outp);
    	
    	remove("students.txt");
    	rename("temp.txt", "students.txt");
    
    }
    
    void read(FILE **inp)
    {
    	student thestudent;
    
    	while(fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF)
    	{
    		printf("%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	}
    }
    
    void grades(FILE **inp)
    {
    	student thestudent;
    	int count = 0;
    	double percentage = 0, result;
    	int editID;
    	*inp = fopen("students.txt", "r");
    	
    
    	while(fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF)
    	{
    		if(thestudent.id == editID)
    		{
    			count = count + 1;
    			if((thestudent.grade = 'A')||(thestudent.grade = 'a'))
    			{
    				percentage = percentage + 85;
    			}
    			else if((thestudent.grade = 'B')||(thestudent.grade = 'b'))
    			{
    				percentage = percentage + 65;
    			}
    			else if((thestudent.grade = 'C')||(thestudent.grade = 'c'))
    			{
    				percentage = percentage + 55;
    			}
    			else if((thestudent.grade = 'D')||(thestudent.grade = 'd'))
    			{
    				percentage = percentage + 45;
    			}
    			else if((thestudent.grade = 'E')||(thestudent.grade = 'e'))
    			{
    				percentage = percentage + 35;
    			}
    			else if((thestudent.grade = 'F')||(thestudent.grade = 'f'))
    			{
    				percentage = percentage + 25;
    			}
    		}
    	}
    	result = (percentage/count);
    	printf("Average percentage for student %d : %.2f\n",editID, percentage);
    	fclose(*inp);
    }
    


    [EDIT] Putting in the code would probably help heh...[/EDIT]


Comments

  • Closed Accounts Posts: 447 ✭✭MickFarr


    Your mising } after else if(option == 4)
    NeoSlicerZ wrote:
    Aight.. I keep getting this one error in my program, makes no sense to me whatsoever. I have a sneaking suspiscion it might be Visual Studio.NET throwing a hissy fit. I get an error c2059: syntax error 'type' in line 50, anyone know what that means? After 2 hours of poking around to fix it, it's driving me to tears.
    #include <stdio.h>
    
    typedef struct stud
    {
    	int id;
    	char name[30];
    	char subject[30];
    	char grade;
    }student;
    
    
    void prompt(void);
    void add(FILE **inp, FILE **outp);
    void edit(FILE **inp, FILE **outp);
    void read(FILE **inp);
    void grades(FILE **inp);
    
    void main()
    {
    	FILE *inp, *outp;
    	int option;
    	
    	do
    	{
    		prompt();
    		scanf("%d", &option);
    		if(option == 1)
    		{
    			add(&inp, &outp);
    		}
    		else if(option == 2)
    		{
    			edit(&inp, &outp);
    		}
    		else if(option == 3)
    		{
    			read(&inp);
    		}
    		else if(option == 4)
    		{
    			grades(&inp);
                              }
    	}while(option != 5);
    
    	
    }
    
    void prompt(void)
    {
    	printf("Please select the option you wish to take\n");
    	printf("1. Add new students to records\n");
    	printf("2. Edit current student records\n");
    	printf("3. Read the file\n");
    	printf("4. Produce a report indicating overall grade for 5 subjects per student\n");
    	printf("5. Quit this program\n");
    }
    
    void add(FILE **inp, FILE **outp)
    {	
    	
    	student thestudent;
    
    	*inp = fopen("students.txt", "r");
    	*outp = fopen("temp.txt", "w");
    
    	//copy the contents of student.txt to temp.txt
    	while((fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF))
    	{
    		fprintf(*outp, "%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	}
    
    	printf("Student ID:\n");
    	scanf("%d", thestudent.id);
    	printf("Name:\n");
    	scanf("%s", thestudent.name);
    	printf("Subject 1:\n");
    	scanf("%s",thestudent.subject);
    	printf("Grade:\n");
    	scanf("%c", thestudent.grade);
    
    	//insert at end of output file
    	fprintf(*outp, "%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	
    	fclose(*inp);
    	fclose(*outp);
    
    	remove("students.txt");
    	rename("temp.txt", "students.txt");
    }
    
    void edit(FILE **inp, FILE **outp)
    {
    	student thestudent;
    
    	int editID;
    	*inp = fopen("students.txt", "r");
    	*outp = fopen("temp.txt", "w");
    	printf("Enter student's ID\n");
    	scanf("%d", &editID);
    
    	while(fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF)
    	{
    		if(thestudent.id == editID)
    		{
    			printf("Student ID:\n");
    			scanf("%d", thestudent.id);
    			printf("Name:\n");
    			scanf("%s", thestudent.name);
    			printf("Subject 1:\n");
    			scanf("%s",thestudent.subject);
    			printf("Grade 1:\n");
    			scanf("%c", thestudent.grade);
    
    		}
    
    
    		fprintf(*outp, "%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	}
    
    	fclose(*inp);
    	fclose(*outp);
    	
    	remove("students.txt");
    	rename("temp.txt", "students.txt");
    
    }
    
    void read(FILE **inp)
    {
    	student thestudent;
    
    	while(fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF)
    	{
    		printf("%d\t%s\t%s\t%c\n", thestudent.id,thestudent.name,thestudent.subject,thestudent.grade);
    	}
    }
    
    void grades(FILE **inp)
    {
    	student thestudent;
    	int count = 0;
    	double percentage = 0, result;
    	int editID;
    	*inp = fopen("students.txt", "r");
    	
    
    	while(fscanf(*inp,"%d\t%s\t%s\t%c",thestudent.id,thestudent.name,thestudent.subject,thestudent.grade) != EOF)
    	{
    		if(thestudent.id == editID)
    		{
    			count = count + 1;
    			if((thestudent.grade = 'A')||(thestudent.grade = 'a'))
    			{
    				percentage = percentage + 85;
    			}
    			else if((thestudent.grade = 'B')||(thestudent.grade = 'b'))
    			{
    				percentage = percentage + 65;
    			}
    			else if((thestudent.grade = 'C')||(thestudent.grade = 'c'))
    			{
    				percentage = percentage + 55;
    			}
    			else if((thestudent.grade = 'D')||(thestudent.grade = 'd'))
    			{
    				percentage = percentage + 45;
    			}
    			else if((thestudent.grade = 'E')||(thestudent.grade = 'e'))
    			{
    				percentage = percentage + 35;
    			}
    			else if((thestudent.grade = 'F')||(thestudent.grade = 'f'))
    			{
    				percentage = percentage + 25;
    			}
    		}
    	}
    	result = (percentage/count);
    	printf("Average percentage for student %d : %.2f\n",editID, percentage);
    	fclose(*inp);
    }
    


    [EDIT] Putting in the code would probably help heh...[/EDIT]


  • Registered Users, Registered Users 2 Posts: 4,287 ✭✭✭NotMe


    You're missing a closing brace on the last if statement in main().

    *edit* hehe MickFarr got there before me :D


  • Registered Users, Registered Users 2 Posts: 2,327 ✭✭✭NeoSlicerZ


    *goes off to kill self*

    It's always the stupid things that kill me :/

    Thanks guys.


  • Closed Accounts Posts: 447 ✭✭MickFarr


    NotMe wrote:
    You're missing a closing brace on the last if statement in main().

    *edit* hehe MickFarr got there before me :D

    ;)


  • Registered Users, Registered Users 2 Posts: 2,327 ✭✭✭NeoSlicerZ


    It gives me an error when I run, saying that the id/grade variables aren't initialised... but I'm scanning em in from a file. The mind boggles.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,184 ✭✭✭causal


    At what point in the run does it give the error?

    Did you get the menu displayed, choose a particular option; or did it not get as far as the menu?

    [stab in dark]
    My C is as rusty as a rusty piece of rust but I'm suspicious where you declare your struct you are creating a varible of that type called 'student'; perhaps your declaration then has to include initial values - see comments added to your code below.
    Now that might be wrong because I'd expect the compiler to pick that up; but if it is right then you might get a similar error with the arrays.
    typedef struct stud
    {
    	int id; //int id =-1;
    	char name[30];
    	char subject[30];
    	char grade; //char grade = 'Z'
    }[B]student[/B];
    
    [/stab in dark]

    causal


Advertisement