0
char input[INPUT_SIZE];  /*Holding user input globaly*/

char history[50][INPUT_SIZE]; /*Storing last 0 commands*/

void addToHistory()
{
  history[0] = input;
  printf("#: %s \n", history[0]);
}

 fgets(input,INPUT_SIZE,stdin) /*Using this to get the input*/

Im using the fgets to save the input, and then i want to be able to called the add to history function to save the current input to the first value in history but i keep getting the error messsgage...

" error: incompatible types when assigning to type ‘char[512]’ from type ‘char *" Ive tryed using &input , *input but its still the same..

I cant seem to solve this..

1 Answer 1

3

You cannot assign to an array, you should copy to it:

memcpy(history[0], input, sizeof(history[0]));
Sign up to request clarification or add additional context in comments.

2 Comments

Or use strcpy(), which avoids copying unused bytes :)
@pmg - you're right, I missed some parts of the question, just saw the assignment :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.