I would really, really appreciate any help on this question as it is somewhat urgent. I am having trouble with a very simple C code in which I need to store an array of char * (Basically, an array of strings) in a struct.
I am getting the error:
error: incompatible types when assigning to type ‘char *[41]’ from type ‘char **’
Here is the relevant code and explanation:
struct HistoryElement
{
int NumberOfCommandGiven;
char * command[MAXLINE/2+1];
};
int main() {
char *args[MAXLINE/2+1];
setup(args); //This gets the command given by user and parses it into args. This works properly.
struct HistoryElement input;
input.command = args; //How to accomplish this without error?
printf("input.command: %s",input.command); //Test
}
The error comes on the line where I am trying to set input.command to args. Although they are both of type char * [], I get the incompatible types error. I am sure this is somewhat simple to fix, but I do not understand what I am doing wrong. An explanation and example would help me ten-fold.
Aucun commentaire:
Enregistrer un commentaire