Hello, please could you tell me where I'm going wrong with this:
Thank youCode:char array[6]; array[0] = {'A', 'B'}; array[1] = {'C'}; array[2] = {'D', 'E', 'F'}; array[3] = {'G'};
Rob Briggs
Hello, please could you tell me where I'm going wrong with this:
Thank youCode:char array[6]; array[0] = {'A', 'B'}; array[1] = {'C'}; array[2] = {'D', 'E', 'F'}; array[3] = {'G'};
Rob Briggs
You've made an array of char. Multidimensional arrays in C are implemented as arrays of arrays, like so:
Now you have 6 arrays, each of which is an array of 10 char. You can't assign to arrays, either, so you'd have to do something like:Code:char array[6][10];
This isn't exactly like your example since strcpy() creates a string by adding a null character; you could assign to each element:Code:strcpy(array[0], "AB");
or use memcpy(), etc.Code:array[0][0] = 'A'; array[0][1] = 'B';
When dealing with arrays, always be careful not to run off the end of one (strcpy() can't check the buffer size, so it's up to you).
There is no way to do this as you. You can try:
Code:char array[][3]={ {'A', 'B'},{'C'},{'D', 'E', 'F'},{'G'} };