array and string terminator

This is a discussion on array and string terminator within the C++ Programming forums, part of the General Programming Boards category; i have several questions about arrays and strings 1) does every line have a terminator in an array? ex int ...

  1. #1
    Registered User bobknows's Avatar
    Join Date
    Jan 2011
    Location
    SD
    Posts
    87

    array and string terminator

    i have several questions about arrays and strings

    1) does every line have a terminator in an array? ex int variable[3][2] = data 0-0, data 1-0, data 2-0, terminator, data 0-1, data 1-1, data 2-1

    2) is there functions already made that can get the sizes used in an array?

    3) when you have a string array and you have to get a certain char from it do you put the location of the char first or the string location first

    4) what happens when you pass an array that is smaller than the one specified
    ex
    Code:
    int func(int array[][][])
    {
         // code here
    }
    int main()
    {
         int array[3][3];
         func(array);
    }
    5) is there a function already made to output an array?

    random question:
    what is the problem with
    Code:
     system("PROGRAM_NAME.exe");
    ?
    when i try to run it it gives an error message

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    1. No, not really - at least if I understand what you're saying. You could write a program that uses arrays with a terminator value like strings, but with different types. NULL or anything like it is good for pointer arrays, or -1 might be good for integer arrays. A terminator can't be valid program values, so picking one for any random plain old builtin type could be hard. The only institutionalized terminator is for C strings, and that terminator is the zero character: '\0', since the functions in cstring library depends on it being present at the end of any C-string.

    2. If you followed 1, you can write a function yourself. Otherwise you're supposed to use a variable with the size in it, if it's a real array. C++ has handy containers though, such as vector, that have a size() method.

    3. Arrays of arrays have to drill-down to get to what you need.

    Code:
    std::string fruits[] = { "Banana", "Orange", "Grape", "Pomegranate" };
    We have a flat array of strings and each first letter is different. 'P' is at fruits[3][0], the third index of fruit--the 0th index of fruit[3].

    4. You should get various compile-time errors, especially with the sample code you gave. It isn't valid because you are missing too many dimension sizes (only the first dimension can be omitted) and passing an array with too few dimensions anyway should never match the parameter type.

    5. No, write one.
    Last edited by whiteflags; 03-06-2011 at 12:16 PM.

  3. #3
    Registered User bobknows's Avatar
    Join Date
    Jan 2011
    Location
    SD
    Posts
    87
    thanks, once i do i will put it in a file and post it here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays of pointers...
    By Programmer_P in forum C++ Programming
    Replies: 60
    Last Post: 05-24-2010, 09:58 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21