Thread: help...! how to eliminate these erros in my code?

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    17

    help...! how to eliminate these erros in my code?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include<windows.h>
    #include <string.h>
    
    
    int main()
    {
        FILE *fp, *ft;
        char another, choice;
    
    
        struct student
        {
            char student_name[30];
    		char matrix_number;
        	char group[20];
        	char cocuricular_activities[15];
        	char lecturer_name[20];
        	char position[20];
        	int  marks;
        	int  attendance;
        };
    
    
        struct student stu;
    
    
        char student_name[30];
    
    
        long int recsize;
    
    
        fp = fopen("STUDENT.DAT","rb+");
        if(fp == NULL)
        {
            fp = fopen("STUDENT.DAT","wb+");
            if(fp == NULL)
            {
                printf("Cannot open file");
                exit(1);
            }
        }
    
    
        recsize = sizeof(stu);
        while(1)
        {
            system("cls");
           	printf("\n***Cocuriculum Activities Record System***");
    		printf("\n1.Add Record\n");
    		printf("\n2.Search Record\n");
    		printf("\n3.Edit Record\n");
    		printf("\n4.List Record\n");
    		printf("\n5.Delete Record\n");
    		printf("\n6.Exit\n");
    		printf("\n Please make your choice :");
    		scanf("%d",&choice);
    		fflush(stdin);
            choice  = getche();
    		switch(choice)
    		{
            case'1':
                system("cls");
                fseek(fp,0,SEEK_END);
    
    
                another = 'y';
                while(another == 'y')
                {
                	printf("\n Name:	");
    				scanf("%s",stu.student_name);
    				printf("\n Matrix number :	");
    				scanf("%d",&stu.matrix_number);
    				printf("\n Group:	");
    				scanf("%s",&stu.group);
    				printf("\n Cocuricular activities:	");
    				scanf("%s",&stu.cocuricular_activities);
    				printf("\n Lecturer Name:	");
    				scanf("%s",&stu.lecturer_name);
    				printf("\n Position:		");
    				scanf("%s",&stu.position);
    				printf("\n Marks:	");
    				scanf("%f",&stu.marks);
    				printf("\n Attendance:	");
    				scanf("%d",&stu.attendance);
    
    
                    fwrite(&stu,recsize,1,fp);
    
    
                    printf("\n Add new reocrd(y/n) ");
                    fflush(stdin);
                    another = getche();
                }
                break;
    		case'2':
    			system("cls");
            	rewind(fp);
                while(fread(&stu,recsize,1,fp)==1)
                {
    			printf("\n Matrix number:	");
    			scanf("%d",&stu.matrix_number);
                }
    			break;
    		case'3':
                system("cls");
                choice = 'y';
                while(choice == 'y')
               {
                    printf("\n Enter student name to edit record:   ");
    				scanf("%s", student_name);
    				rewind(fp);
    				while(fread(&stu,recsize,1,fp)==1)
    			{
    			      if(strcmp(stu.name,student_name) == 0)
    				   {
    					printf("\n Enter new student name:	");
    					scanf("%s",stu.student_name);
    					printf("\n Enter new matrix number:	");
    					scanf("%d",stu.matrix_number);
    					printf("\n Enter new group:	");
    					scanf("%s",stu.group);
    					printf("\n Enter new cocuricular activities:	");
    					scanf("%s",stu.cocuricular_activities);
    					printf("\n Enter new lecturer name:	");
    					scanf("%s",stu.lecturer_name);
    					printf("\n Enter new position:	");
    					scanf("%s",stu.position);
    					printf("\n Enter new marks:	");
    					scanf("%f",stu.marks);
    					printf("\n Enter new attendance");
    					scanf("%d",stu.attendance);
    					fseek(fp,-recsize,SEEK_CUR);
                        fwrite(&stu,recsize,1,fp);
                        break;
                      }
    
    
               }
    		printf("\n Edit another record(y/n)");
        	fflush(stdin);
        	another = getche();
                 }
      		break;
            case'4':
                system("cls");
                rewind(fp);
                while(fread(&stu,recsize,1,fp)==1)
                {
                    printf("\n %s,name.stu");
                    printf("\n %d,matrix_number.stu");
                    printf("\n %s,group.stu");
                    printf("\n %s,cocuricular_activities.stu");
                    printf("\n %s,lecturer_name.stu");
                    printf("\n %f,marks.stu");
                    printf("\n %d,attendance.stu");
                }
                getch();
                break;
            case'5':
                system("cls");
                another = 'y';
                while(another == 'y')
                {
                	printf("\n Enter name of student to delete record:	");
        			scanf("%s",student_name);
        	    	ft = fopen("temp.dat","wb");
        	    	rewind(fp);
                	while(fread(&stu,recsize,1,fp) == 1)
                    {
                    	if(strcmp(stu.name,student_name) != 0)
                        {
                            fwrite(&stu,recsize,1,ft);
                    	}
                	}
                    fclose(fp);
                    fclose(ft);
                    remove("STUDENT.DAT");
                    rename("Student.dat","STUDENT.DAT");
                    fp = fopen("ESTUDENT.DAT", "rb+");
                    printf("Delete another record(y/n)");
                    fflush(stdin);
                    another = getche();
                }
                break;
            case'6':
            fclose(fp);
            exit(0);
            }
        }
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2015
    Posts
    17
    C:\Users\USER\Documents\programming basic assignment\vv1.c|108|error: 'struct student' has no member named 'name'|
    C:\Users\USER\Documents\programming basic assignment\vv1.c|163|error: 'struct student' has no member named 'name'|

    i don't understand what reasons lead to these two errors.
    how to eliminate them?
    could anyone show me?
    thanks a lot!

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > C:\Users\USER\Documents\programming basic assignment\vv1.c|108|error: 'struct student' has no member named 'name'|

    You look at your struct and discover that it's actually called student_name
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    spaghetticode
    Guest
    Quote Originally Posted by Carlies View Post
    i don't understand what reasons lead to these two errors.
    This is not meant as an offense, but, I really wonder if you even read the error messages. This one says absolutely literally what is wrong, in plain English. No compiler can ever get as clear as with this error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Eliminate title
    By ulti-killer in forum C Programming
    Replies: 8
    Last Post: 06-17-2012, 08:38 AM
  2. new to C...need to eliminate whitespace
    By cakestler in forum C Programming
    Replies: 7
    Last Post: 02-02-2009, 12:41 PM
  3. How to eliminate irrelevant conditionals?
    By cdave in forum C Programming
    Replies: 9
    Last Post: 12-10-2005, 04:39 PM
  4. How to eliminate extra whitespaces?
    By dat in forum C Programming
    Replies: 1
    Last Post: 10-24-2002, 06:42 PM