Thread: Help with putting data into an array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Quote Originally Posted by Tek12x View Post
    Does C know to put the char into the right place and the int into the right place?? What if the is only 5 numbers?? Will the other 4 have 0 place in the values??
    If you declare the structure outside(global) any function, including main(), I think the array elements will all be initialized to zero.

    EDIT: I've have just tested this by declaring a global structure(with an int array). I printed out the array's values, and they were all zero. So they have all been initialized to zero.

    fscanf() will only read what it can for each line, and put the values into array number[i]. For the values fscanf() can't read(because there is nothing to else read), the array elements will be already initialized to zero.

    And the structure should look like this.
    Code:
    struct data {
        char firstname[10]; 
        char lastname[15];
        char line[LINELENGTH];           / * stores each line in here */
        int number[7];
    } Information[MAXSCORES];
    Last edited by happyclown; 01-20-2009 at 08:20 PM.
    OS: Linux Mint 13(Maya) LTS 64 bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Replies: 19
    Last Post: 12-17-2007, 02:57 AM
  3. Replies: 1
    Last Post: 09-10-2005, 06:02 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM

Tags for this Thread