Computers |
|
| | #1 (permalink) |
| True Techie Join Date: May 2006
Posts: 101
| I am relativaly new to c++, i know most of the basics about programming but i dont know about any functions, and im wondering if there is a function to display the contents of an array and a function to return the length of an array
__________________ .:HP Pavillion dv6000:. 1.8 ghtz Intel Core 2 Duo 2GB RAM 120 GB HDD nVidia Go graphics Apache 2.2 (looking for a domain name) |
| | |
| | #2 (permalink) |
| Resident Badass Join Date: Jul 2005
Posts: 821
| well, on the problem of displaying the contents of a array, you can just run a simple loop add 1 to a count variable, each time showing the contents of the array Example: void printarray (int number[], int length) <--calling this from the main program { for (int n=0; n<length; n++) cout << number[n] << " "; cout << "\n"; } Sry if the code isn't 100% correct; the fundamentals are right.
__________________ |
| | |
| | #3 (permalink) |
| True Techie Join Date: May 2006
Posts: 101
| is there a way to return the length of an array so i dont have to keep track of a variable with it?
__________________ .:HP Pavillion dv6000:. 1.8 ghtz Intel Core 2 Duo 2GB RAM 120 GB HDD nVidia Go graphics Apache 2.2 (looking for a domain name) |
| | |
| | #4 (permalink) |
| Monster Techie Join Date: May 2004 Location: /usr/root/mn/us
Posts: 1,096
| There are a couple of ways to do this. The first is to always make sure the end of your array has a termination character (such as null or an empty string "") Then when you loop through the array have the termination criteria be i == NULL or i == "" The other way is to keep track of the length of your array from the beginning of your program. For example, declare your array to be a specific length at the very start of your program or procedure. There is no built in length() function for C/C++ arrays
__________________ ![]() Its a frigging Laptop, not a Labtop!!!! |
| | |