array of strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bravephantom
    New Member
    • Dec 2006
    • 27

    array of strings

    how can i specify the length of strings to be put in an array??
    for example if i have array[100]
    i want to fill each position in the array with a string of exactly 30 spaces
  • Extremist
    New Member
    • Jan 2007
    • 94

    #2
    Originally posted by bravephantom
    how can i specify the length of strings to be put in an array??
    for example if i have array[100]
    i want to fill each position in the array with a string of exactly 30 spaces
    Please spesify c++ or C

    in C++:

    You can simply say:
    Code:
    string stringarray[100];
    In C:

    Code:
     char *stringarray[100];

    Comment

    • bravephantom
      New Member
      • Dec 2006
      • 27

      #3
      Originally posted by Extremist
      Please spesify c++ or C

      in C++:

      You can simply say:
      Code:
      string stringarray[100];
      well i meant C++
      that way we now have array with 100 positions but didnt specify the length of each yet
      thnx for reply

      Comment

      • Indianraja
        New Member
        • Apr 2007
        • 22

        #4
        Originally posted by bravephantom
        how can i specify the length of strings to be put in an array??
        for example if i have array[100]
        i want to fill each position in the array with a string of exactly 30 spaces
        just try with double dimension array suppose if u declare as lik a[100][30] then 100 represent 100 persons and 30 represents no of char...

        Comment

        • Extremist
          New Member
          • Jan 2007
          • 94

          #5
          You can use the char* version as well in C++ , the only thing that would happen is that as soon as you give it a value, it would take that as it's size, you don't have to explicidly define a size

          So, lets say you give it a value of 30 characters, it would take it as size 30.
          No need to define the size in the case of character arrays

          Comment

          Working...