plllllllllz help me

Discussion in 'C' started by saraali, Mar 2, 2011.

  1. saraali

    saraali New Member

    Joined:
    Mar 2, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    i do not want to make the program receives the data had previously been introduced

    plz help me

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    int hour[10];
    FILE *p;
    struct address
    {
    char city[20],town[20],street[20];
    int homeno;
    };
    struct studentdata
    {
    int num;
    float gpa;
    char name[20];
    char ***[5];
    int deg[10];
    struct address add;
    struct studentdata *next;}data ,temp;
    //get function
    void getdata()
    {
    
    fflush(stdin);
    printf("name:\n");
    scanf("%s",temp.name);
    printf("***:\n");
    scanf("%s",temp.***);
    printf("city:\n");
    scanf("%s",temp.add.city);
    printf("town:\n");
    scanf("%s",temp.add.town);
    printf("street:\n");
    scanf("%s",temp.add.street);
    printf("home number:\n");
    scanf("%d",&temp.add.homeno);
    for(int i=0;i<10;i++)
    
    {
    printf("\nsubject %d :",i+1);
    scanf("%d",&temp.deg[i]);
    printf("hour for subject %d :",i+1);
    scanf("%d",&hour[i]);
    }}
    //gpc function
    void	gpc()
    {
    int	point,sumh=0,sump=0,j;
    
    for(j=0;j<10;j++)
    { point=((temp.deg[j])*(hour[j]))/25;
    sump=sump+point ;
    sumh=sumh+hour[j];
    }
    temp.gpa=sump/sumh;
    
    }
    //search function
    void search(int num)
    {
    
    p=fopen("data.txt","r");
    if(p==NULL)
    {printf("erorr");
    exit(0);
    }
    else
    {
    while(!feof)
    {fseek(p,sizeof(studentdata),SEEK_SET);
    fread(&temp,sizeof(studentdata),1,p);
    if(num==temp.num)
    break;
    }
    //when the pointer in the end of file
    }}
    
    void main()
    {//being program
    int no;
    FILE *ptr;
    scanf("%d",&no);
    search(no);
    if(no!=temp.num)
    { getdata();
    temp.num=no;
    gpc();
    
    ptr=fopen("data.txt","a");
    if(ptr==NULL)
    {printf("error");
    exit(0);}
    
    else
    {
    fprintf(ptr,"%d%s%s%s%s%s%d%f",temp.num,temp.name,temp.***,temp.add.city,temp.add.town,temp.add.street,temp.add.homeno,temp.gpa);
    for(int i=0;i<10;i++)
    fprintf(ptr,"%d",temp.deg[i]) ;
    fclose(ptr) ;
    }
    
    }	 }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice