One of the lovely things about C...
Check line 5 of changeSetting(): you've got the ; on the wrong side of the }.
Every single statement in C must be terminated by a semi-colon. It's the little things that get you...
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
There's nothing wrong with your code except:
strcpy(tempSettings->setting[indexValue], newValue)};
that semicolon needs to be before the closing }I think it's something to do with the last line in changeSetting function, but I can't point where exactly! Am I supposed to add brackets somewhere ? ( i.e. (*tempSettings)->etc ) or is the problem with me using "->" instead of "." to access the members ? or is it some problem / limitation with C pointers/structures/2D-arrays-in-structures ?
you can do(*tempSettings).setting[indexValue] or what you just wrote tempSettings->setting[indexValue]. Both are the same.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
Assuming the ; is a typo (it won't even compile), then it seems fine here (cygwin/gcc)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct settings {
char setting[40][255];
};
void changeSetting(struct settings *tempSettings, char *newValue,
int indexValue)
{
if (indexValue < 40) {
strcpy(tempSettings->setting[indexValue], newValue);
}
}
int main()
{
struct settings MySettings;
changeSetting(&MySettings, "penguin", 0);
printf( "Penguin Power=%s\n", MySettings.setting[0] );
return 0;
}
$ gcc -W -Wall -ansi -pedantic foo.c
$ ./a.exe
Penguin Power=penguin
Your struct is about 10K in size. This shouldn't be a problem if your compiler is a 32-bit compiler, but some old 16-bit compilers used very small (like 3K) stack sizes, and this would obviously blow that right out of the water.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953