Thread: Reading from an input file + processing

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    2

    Reading from an input file + processing

    Hey guys,

    Wondering if anyone can point me in the right direction as im almost a complete C programming Virgin.

    Been asked to write a lottery program (using GCC compiler) that reads from an input file (Input.dat) and then processes the info to provide a report specifying :-

    Date
    winning numbers
    sums of prizes per match
    players name
    multiple tickets
    terminating line

    Ive got a vague idea of how to work out the loops and arrays, however - im not sure how to get the data from the input file and put it into something i can use.

    My attempt so far looks like this :-

    Code:
     #Include <stdio.h>
    #include <string.h>
    
    Int Main ()
    
    {
    
    Char text [25];
    FILE *file_ptr;
    file_ptr = fopen ("Input.dat", "r+");
    
    if (file_ptr !=NULL);
    
    {
    
    While fgets (char, 25, file_ptr) !=NULL)
    
    }

    Is this the right way to open an input file ? and how do i use the numbers + text from the input ?

    really confused.

    oh, and the input file looks like :-

    20 10 2007
    4 15 25 27 33 40 20
    10 78 2384 909414 119922
    John Smith
    6 8 15 17 23 33
    4 15 26 27 40 46
    8 11 25 27 33 40

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Is this a real code?

    #Include
    should be
    #include

    Int
    should be
    int

    Code:
    While fgets (char, 25, file_ptr) !=NULL)
    should be

    Code:
    while( fgets (text, sizeof text, file_ptr) !=NULL)
    {
    }
    etc...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    2
    couldnt cut and paste it from VirtualBox, the capitals arent there in code.


    Like i said though - im not really sure i know what im doing.



    For the (text, Sizeof text, file_ptr) part I thought i needed to insert the values myself ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. C++ Input File Reading Help!
    By beast0000 in forum C++ Programming
    Replies: 3
    Last Post: 01-03-2009, 10:12 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. error reading input from file
    By drharv in forum C Programming
    Replies: 3
    Last Post: 06-12-2002, 05:43 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM