Reading data from a file

This is a discussion on Reading data from a file within the C Programming forums, part of the General Programming Boards category; Hi, Can someone please explain me the following code I don't understand the question. Thanks Code: #include <stdio.h> #include <stdlib.h> ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    5

    Reading data from a file

    Hi,
    Can someone please explain me the following code I don't understand the question.
    Thanks

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    /**
       Source: q1.c
       --------------
       Write a program in C to do the following.
       For each of the three datasets in input1.txt
         Read integer n
         Read n integers and add them up.
         Write the sum of the n integers to stdout (no words, just the sum).
         ---------------------------------------------------
         EXPECTED OUTPUT:
         6
         30
         417
     */
    
    
    
    
    int main (void) 
    {
      int i, j, n, sum, value ;
      FILE * inp ;
      inp = fopen("input1.txt", "r") ;
      if (inp == NULL) {
        printf("Could not find input file: input1.txt\n") ;
        exit(1) ;
      }
      //----------------Start below here. To do: approximate lines of code = 9
      // 1. See instructions above.
      
    
    
    
    
    
    
    
    
    
    
      //----------------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
      exit(0) ;
    }

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    5
    The input file:
    3
    1 2 3
    2
    14 16
    10
    15 13 10 3 18 4 15 17 100 222

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 05-31-2009, 11:30 AM
  2. Reading data from a file..
    By lamiamike in forum C++ Programming
    Replies: 4
    Last Post: 02-23-2006, 01:54 PM
  3. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  4. Reading in data from a file
    By neandrake in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 08:04 PM
  5. reading data from a file
    By brianptodd in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2003, 05:50 PM

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