probelms regarding file processing

This is a discussion on probelms regarding file processing within the C Programming forums, part of the General Programming Boards category; hello again! i've been trying different permutations of the code u suggested so now, my prog looks something like that: ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    9

    probelms regarding file processing

    hello again!
    i've been trying different permutations of the code u suggested so now, my prog looks something like that:

    #include <stdio.h>

    main()
    {
    FILE *file3 = fopen("f1.dat", "r");
    FILE *file4 = fopen("f2.dat", "r");
    FILE *file5 = fopen("f3.dat", "w");

    int c, d, a, b, ret1, ret2;

    ret1 = fscanf(file3, "%d", &a);
    ret2 = fscanf(file4, "%d", &b);

    while(ret1 && ret2){
    if (a >= b){
    fprintf(file5, "%d\n", b);
    ret2 = fscanf(file4, "%d", &b);
    }
    else{
    fprintf(file5, "%d\n", a);
    ret1 = fscanf(file3, "%d", &a);
    }
    }

    if(ret1){
    do{
    fprintf(file5, "%d\n", a);
    ret1 = fscanf(file3, "%d", &a);
    }
    while(ret1);
    }

    if(ret2){
    do{
    fprintf(file5, "%d\n", b);
    ret2 = fscanf(file4, "%d", &b);
    }
    while(ret2);
    }
    }

    ************************************************** ***************
    I used test values as follows:
    f1.dat is 10 20 30 40 50
    f2.dat is 15 25 35 45 55 65 75 85

    after running the prog, however, i opened f3.dat and found that the values were as follows:
    10 15 20 25 30 35 40 45 50 50 50 50...................all the way...
    i can't seem to solve the prob...however, if i use the normal !feof way, it works ok... as in if i use
    while(!feof(file4))
    etc as a condition...

    any comments??
    Thanks a million!

  2. #2
    Sayeh
    Guest
    Could you perchance provide a single sentence explaining what it is you're wanting to do?

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    9
    yeah i'm so sorry...the aim is to read an already sorted list of integers in f1.dat and f2.dat.
    Thereafter, upon reading the data from each file, it will sort the integers and transfer it to f3.dat...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. file processing updating record error
    By uuser in forum C Programming
    Replies: 2
    Last Post: 04-27-2003, 12:13 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21