# Thread: two dimensional string array question

1. ## two dimensional string array question

Does anyone here have any tips on how to fill a two dimensional string array with a scanf() function. I know this is not the best way to do it, but it's what I'm supposed to use. I'm writing a program that asks the user for 7 strings of input. I need to use the preprocessing directive:

Code:
`#define   N_Strings     7`
so I figured a two dimensional array would work well. Something like:

Code:
`w[N_Strings][100]`
Could you help me figure out how to read in the 7 strings so they are put in the right spot.

2. Code:
```for(i = 0;i < N_Strings;++i)
scanf("%s", w[i]);```

3. Am I correct in saying that w[0] is a pointer to the first row,w[1] is a pointer to the second row,...... w[i] is a pointer to the i-th row or is this wrong? (just trying to understand the concept)

4. Also,how would you test for a newline in there?
would this work:
Code:
```for(i = 0; i < N_Strings; ++cnt);
if( w != '\n')
scanf("%s", w[i]);```

5. i meant ++i on the end of the for statement.

6. Originally Posted by Hoser83
i meant ++i on the end of the for statement.
That's what the edit button is for.

7. Originally Posted by Hoser83
Also,how would you test for a newline in there?
would this work:
Code:
```for(i = 0; i < N_Strings; ++cnt);
if( w != '\n')
scanf("%s", w[i]);```

Consider researching the strchr() function to find a certain character in a character array.

8. Originally Posted by Hoser83
Also,how would you test for a newline in there?
would this work:
Code:
```for(i = 0; i < N_Strings; ++cnt);
if( w != '\n')
scanf("%s", w[i]);```
you got to say w[i] in the if statmenet a well. otherwise u are just checking the w[0]th string b'cose the w is the base address and the i is the off set. changes made code will soemthing look as follow

Code:
```if(w[i] != '\n')
....
....```
as said strchr() is the best to do this kinds of things

ssharish2005

9. thanks man, I appreciate it!