Thread: One final Array question

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    36

    One final Array question

    My program should work for any number of items up to 100. My file that I am scanning into my array only contains something like 31 integers. How can i scan only those integers into my array and them print them to the user? As I stand right now, I am printing 31 numbers, followed by 69 zeros. Here is my code for the scanning/printing:

    Code:
    /* Get all the data from the file */
    	for (i = 0; i < SIZE; i++) 
    	{
    		fscanf(inp, "%d", &temp[i]);
    	}
    	
    	/* Print all the data from the file */
    	for (j = 0; j < i; j++)
    	{
    		printf("%d\n", temp[j]);
    	}

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    This was already explained in the other thread you started. Just check the return code of fscanf, and stop then. Keep a count of how many lines you received. See the posts in that thread relating to it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Array of Structs question
    By WaterNut in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2004, 02:58 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM