Originally posted by Unregistered
if i have 2D array char info [2][8];
[2 9 0 5 J O H N]
[3 5 5 2 1 i a n ]
Just a small point...... If you are using these array as strings, you need to create the rows 1 longer than the string itself to allow for the NULL terminator.
As for copying parts of a string, you can do this a few ways. One is to use strncpy(), which allows you to copy upto n characters from one char array to another (just watch out the the null terminator that isn't necessary appended to the target). Or you can make a bit of code to do the copy yourself. Something like
Code:
for (i = 0; i < 4; i++)
target[i] = source[i];
Again, you will need to take care of NULL terminator if you intend to use these as strings.
[EDIT] In your case, the source array in my sample code would be coded like this: source[0][i]
The 0 would be replaced with the relevant index number for the string you want to work with. Here's a working example:
Code:
#include <stdio.h>
int main(void)
{
int i;
char *source[] = {"abcdefgh", "ijklmnop"};
char target[100];
for (i = 0; i < 4; i++)
target[i] = source[0][i];
target[i] = '\0';
printf("source[0]: %s\n", source[0]);
printf("target: %s", target);
return (0);
}