beginner at c programming...how to manipulate multiple files in a single program?

This is a discussion on beginner at c programming...how to manipulate multiple files in a single program? within the C Programming forums, part of the General Programming Boards category; I have 3 files i need to read in one program.. the files contain the same type of information.. numbers, ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    4

    Question beginner at c programming...how 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??

    Code:
    #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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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


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