Thread: String Array fgets

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    18

    String Array fgets

    If you are using fgets to put strings into an array of strings are the strings represented by the first or second declared dimension of the array.

    For instance is you had array str[32][310] would that be able to read 310 strings of 32 members or 32 strings of 310 members?

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    str[0][0] would be the start of your first string.
    str[1][0] would be the start of your next.
    and so on,
    str[31][0]

    you can think of it as,
    str[rows][columns]
    or
    str[str_no][letters]

    And that is regardless of how you go about filling the arrays.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    32 strings of 309 characters (remember one byte for the null terminator). str[0] is your first string of 309, str[1] your second, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fgets erroneoulsy returns null string
    By leonv in forum C Programming
    Replies: 3
    Last Post: 12-04-2006, 06:20 AM
  2. Replies: 7
    Last Post: 12-01-2005, 12:17 PM
  3. is scanf as safe as fgets when used to receive string?
    By Antigloss in forum C Programming
    Replies: 4
    Last Post: 08-31-2005, 05:18 PM
  4. String manipulation and scanf vs fgets
    By Nit in forum C Programming
    Replies: 9
    Last Post: 03-20-2002, 12:44 PM
  5. Problem with fgets and getting the string
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 10-03-2001, 02:22 PM