0

I have the struct:

struct person {
    char firstname[];
};

And the method:

void abcde (person* a, char firstchar[]) {
    a->firstname = firstchar;
}

The gcc throws this:

incompatible types in assignment of char*' tochar[0u]'

How to solve this problem? Thanks for help!

2
  • Shouldn't you have struct person * a as the formal parameter? You are missing struct. Commented May 25, 2013 at 21:53
  • @unxnut the OP is probably using a C++ compiler. Commented May 25, 2013 at 22:34

1 Answer 1

2

You cannot assign to an array. you want either a pointer, or copy the content of one into another.

struct person {
    char* firstname;
};

void abcde (person* a, char firstchar[]) { 
    a->firstname = firstchar;
}

firstchar in the function parameters is a pointer, not an array! the [] is merely a syntactic convenience. This is not the case for char firstname[];, which is an array.

Sign up to request clarification or add additional context in comments.

Comments

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.