Thread: Reading Data from Text and Inputing into another

  1. #1
    naynay_23
    Guest

    Reading Data from Text and Inputing into another

    Could someone tell me what I am doing wrong, I am trying to put them in columns on the output with Headers of ID, Score1, Score2, Average. here is what I have.
    #include <stdio.h>

    int main()
    {
    int id;
    float score1;
    float score2;
    float avg;
    FILE *scores;
    FILE *scores1;
    scores=fopen("scores.dat","r");
    scores1=fopen("scores.out","w");
    while (!feof(scores) )
    {
    avg=(score1+score2)/2;
    fscanf(scores, "%i%f%f%f",&id, &score1, &score2, &avg);
    fprintf(scores1,"ID%i \t\t Score1%.2f \t\t Score2%.2f\t\t Average%.2f\n",id, score1,score2,avg);
    }

    fclose(scores);
    fclose(scores1);

    return 0;
    }

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    You're calculating your average before inputting the values necessary to do that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inputing Character Data
    By azndragon247 in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2006, 11:42 AM