Thread: Can somebody explain this?

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    48

    Can somebody explain this?

    I'm suppose to use this prototype : char **read_lines(FILE *fp) for a function. The function is should read all lines in a given file and store them in a NULL-terminated array of strings.

    What is going on in the header for the function? and also what does this mean by an array of strings and how does that work out? Thanks for any help so I can get a better understanding on what I am to do.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    an array of strings is a 2D array of chars. Thus a char**. This is what you are going to return back in main.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    48
    What do the two values correspond to then lines[x][y]?

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    If lines is the name of your array, then line[x][y], would be a char, a letter. line[x] would be a string.

    Take a picture.
    Can somebody explain this?-str-jpg
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    For each line read, malloc a chunk of memory big enough to hold the string. Save its address in another array that's also malloced. Return the address of that pointer array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone explain this one?
    By BEN10 in forum Tech Board
    Replies: 16
    Last Post: 09-06-2009, 11:36 AM
  2. please explain
    By moment in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2009, 08:20 AM
  3. can anyone explain this?
    By anntenna333 in forum C Programming
    Replies: 6
    Last Post: 04-26-2006, 09:38 AM
  4. Please explain this to me
    By kermit in forum C Programming
    Replies: 5
    Last Post: 10-01-2003, 05:07 PM
  5. Someone explain it please
    By yakabod in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2003, 05:30 PM