![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
static array...
hello everyone..
first of all lemme just post a few lines of code so that it's easier to explain the "problem". int main()
{
int n;
int index[100];
float average[100];
char name[100][20];
while((n<0) || (n>100))
{
cout << "How many students?" << endl;
cin >> n;
while(!cin)
{
cin.clear();
cin.ignore(100,'\n');
cout << "Input the NUMBER of students" << endl;
cin >> n;
cin.get();
}
}.......so...my question is regarding the char name variable. let's say if i was using dynamic array..i would first ask for the number of students (cin >> n , and then create a pointer to a variable... char (*name)[30] = new char[n][30]; but now...since i'm using static array, how do i do that? first defining the variable char name[100][30] (for eg 100 is the number of students), and THEN asking for the number of students doesn't make any sense does it? because...what if i answer that there are 200 students and the array is set to 100 ?? could be a stupid question but i've been using 99% dynamic allocation lately. |
|
|
|
|
|
#2 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|