Pelles C forum
C language => Beginner questions => Topic started by: colddax on July 09, 2007, 06:42:53 PM
-
Hello Everyone.
I have a question regarding the use of multidimensional arrays.
Lets say I have the following code segment
char file[1][200];
... and later on I copy something to the file array
strcpy(&file[0][0],"Testing 123");
How would I access just the "T" in "Testing"? Accessing &file[0][0] gives me "Testing 123".
Would I need to do something like this &file[0][0][0]?
Thanks for any help you can provide.
;D
-
You know what, I think I just figured it out. I believe it is file[0][0]. I was just using it incorrectly.
-
Hello
Here is the correct code:
#include <stdio.h>
#include <string.h>
void main(void)
{
char file[1][200];
strcpy(file[0], "Testing 123");
printf("%c\n", file[0][0]); // Display the T
printf("%s\n", file[0]); // Display the entire string
}
There is no need to add &
If you want to use it, you have to add [ 0 ] in order to "cancel" the & character.
-
Thanks so much!