Pelles C forum

C language => Beginner questions => Topic started by: colddax on July 09, 2007, 06:42:53 PM

Title: Using multidimensional arrays
Post 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

Code: [Select]
char file[1][200];

... and later on I copy something to the file array

Code: [Select]
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
Title: Re: Using multidimensional arrays
Post by: colddax on July 09, 2007, 07:22:35 PM
You know what, I think I just figured it out. I believe it is file[0][0]. I was just using it incorrectly.
Title: Re: Using multidimensional arrays
Post by: skirby on July 09, 2007, 08:41:56 PM
Hello

Here is the correct code:
Code: [Select]
#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.
Title: Re: Using multidimensional arrays
Post by: colddax on July 09, 2007, 09:44:41 PM
Thanks so much!