Click here to Skip to main content
13,002,628 members (64,123 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am beginner in c++
i have defined a 2d char array,now how can i input data in it?

int i;
char str[100][100];
for (i=0;i<100;i++)

i want to save string in each row in array
this is my code but it doesn't work!
Posted 20-Apr-11 7:35am
Updated 20-Apr-11 7:53am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Not sure what your goal is, but perhaps something like this:

int i;
char str[100][100];
for (i=0;i<100;i++)
  for(int j=0; j<100; j++)
    cin >> str[i][j];

Note, that's just untested pseudocode. But note how I've used 2 indices there.


His alternate thread where he described it with more details (the key point about strings vs chars) has been answered here:

list of strings in an 2d array[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170626.1 | Last Updated 20 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100