First, I define a struct of char arrays (strings) and then try accessing the same. I get an "incompatible types in assignment" error:
Expand|Select|Wrap|Line Numbers
- struct {
- char name[50];
- char value[50];
- } varlist[20];
- int main(int argc, char *argv[]) {
- varlist[0].name = "foo";
- varlist[0].value = "bar";
- }
The second question I think has to do with a pointer issue, but I'm not sure.
Expand|Select|Wrap|Line Numbers
- char *mymethod(char str[]){
- char *result = malloc(100*sizeof(char));
- strcpy(result, atoi(global_variable));
- // global_variable is defined in a header file
- return result;
- }
When I run it, I get a "Passing arg 1 of 'atoi' makes pointer from interger without a cast" and I get the same error for arg 2 of strcpy.
Please help, and thanks in advance.