Thread: beginner at c to manipulate multiple files in a single program?

  1. #1
    Registered User
    Join Date
    Nov 2010

    Question beginner at c to manipulate multiple files in a single program?

    I have 3 files i need to read in one program.. the files contain the same type of information.. numbers, but in each file the numbers are different.

    i wrote a program to read one file and manipulate the information in it, but i need to get this program to somehow read the other two files right after this one, and i'm unsure of what i need to do. this is it...

    could i write a function to read these 3 files??

    #include <stdio.h>
    main ()
        FILE *ontariofile;
        int beachnum, sampnum, s;         
        double samp,total, avg;
        ontariofile = fopen ("ontario.txt", "r");
        while (fscanf (ontariofile, "%d", &beachnum) != EOF)
            total = 0;
            fscanf (ontariofile, "%d", &sampnum);
                    for (s = 1; s <= sampnum; ++s)
                        fscanf (ontariofile, "%lf", &samp);
                        total = total + samp;
                    avg = total / sampnum;
                    if (avg > 50)
                        printf ("%d: open\n", beachnum);
                    else if (avg < 50)
                    printf ("%d: closed\n", beachnum);
                if (sampnum <3) 
                    printf ("%d: insufficient data\n", beachnum);
    fclose (ontariofile);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. Builder C++ large files support for simple C program
    By Murfury in forum C Programming
    Replies: 3
    Last Post: 11-23-2007, 03:47 PM
  3. Compiling Multiple files in a single Project
    By pdwivedi in forum C Programming
    Replies: 2
    Last Post: 10-08-2007, 05:14 AM
  4. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM

Tags for this Thread