Computing.Net > Forums > Programming > Array Loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Array Loop

Reply to Message Icon

Name: Grune
Date: February 20, 2002 at 09:47:14 Pacific
Comment:

I have a char name[20]. I want to insert one letter at a time into this array. So I am doing this:

char name [20];
int key;

key = getch();
name[1] = key;
key = getch();
name[2] = key;
key = getch();
name[3] = key;
key = getch();
name[4] = key;
key = getch();
name[5] = key;
key = getch();
name[6] = key;
key = getch();
name[7] = key;
// And so on...

I would rather loop this if possible. How is this done? My problem is say name[1] and then somehow change it to name [2] in the loop. i tried saying name++, but it doesn't work for char I think. If this is not clear please say so. Thank you



Sponsored Link
Ads by Google

Response Number 1
Name: Tom
Date: February 20, 2002 at 10:47:56 Pacific
Reply:

No, see it would be like this:
char name[20];
int key;
int index = 0;

while(...){
key = getch();
name[index] = key;
index++;
}

unless you use pointers...


0

Response Number 2
Name: Grune
Date: February 20, 2002 at 12:33:46 Pacific
Reply:

Ok so let me see if I understand this.

"Index" is being passed to "name". Right? And "Index" being incremented by 1 each time the the loop complets. Thanks


0

Response Number 3
Name: Grune
Date: February 20, 2002 at 13:40:25 Pacific
Reply:

Hey man I tried it and it worked!!! Thank you very much!!!


0

Response Number 4
Name: Wndrr
Date: February 22, 2002 at 06:48:07 Pacific
Reply:

I know maybe you can not see this, but I want to tell you that you should now do something basic...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Array Loop

lists. arrays going into www.computing.net/answers/programming/lists-arrays-going-into/8064.html

array manipulation www.computing.net/answers/programming/array-manipulation/9269.html

VB6 Array help needed www.computing.net/answers/programming/vb6-array-help-needed/1883.html