data file processing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghostme
    New Member
    • Oct 2006
    • 1

    #1

    data file processing

    Hello good pple of the forum
    Now i have created a text file using c with the following code:
    [PHP]main()
    {
    int id;
    char firstname[20];
    char lastname[20];
    FILE *pt;
    if((fp=fopen("c lient.txt","w") )==NULL)
    {
    puts("sorry can't open file");
    }
    else{
    do{
    scanf("%d %s %s", &id, firstname, lastname);
    fprintf("%d %s %s\n", id, firstname, lastname);
    }
    while(!feof(std in));
    }
    return 0;
    }
    [/PHP]

    Now with the above code i can insert customer records with id, firstname, lastname into the file. Now, my question is how do search this file for a particular customer record using the id number as a search criteria?
    please help me
    Thank you in advance
  • zahidkhan
    New Member
    • Sep 2006
    • 22

    #2
    Originally posted by ghostme
    Hello good pple of the forum
    Now i have created a text file using c with the following code:
    [PHP]main()
    {
    int id;
    char firstname[20];
    char lastname[20];
    FILE *pt;
    if((fp=fopen("c lient.txt","w") )==NULL)
    {
    puts("sorry can't open file");
    }
    else{
    do{
    scanf("%d %s %s", &id, firstname, lastname);
    fprintf("%d %s %s\n", id, firstname, lastname);
    }
    while(!feof(std in));
    }
    return 0;
    }
    [/PHP]

    Now with the above code i can insert customer records with id, firstname, lastname into the file. Now, my question is how do search this file for a particular customer record using the id number as a search criteria?
    please help me
    Thank you in advance

    Use fscanf in while loop until id == desired id

    Comment

    Working...