reading more than 1 string in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asdfjkl
    New Member
    • Mar 2010
    • 1

    reading more than 1 string in c

    i'd like know how to read more than 1 string without using a structure and display them
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    ? Couldn't you have multiple char* 's, then output them with printf?

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      A string in C is usually or always (?) held in an array characters of length n-1 to allow a space for the NULL character '\0' . You can get the number of elements using sizeof(); <sizeof() becomes the terminating argument in the for loop
      So if you had say three arrays each containing a string of characters you could read them with two for loops.
      The first loop would pick the array say char_string s1 then char_string s2 then char_string s3
      The second loop would display the individual elements of each array in turn.
      Does this fit with what you had in mind?

      Comment

      • sridhard2406
        New Member
        • Dec 2007
        • 52

        #4
        declare the array of pointers, then allocate the memory for, when string is initialzed, let me know, do u got a picture of your question?

        Comment

        Working...