Prince of Persia
Prince of Persia

Reputation: 49

Use of undeclared identifier when using struct?

When I try to assign char string_buffer in another struct it says

error use of undeclared identifier

I know that means it I need to declare string buffer in the current struct but is there a way without doing this.

struct ABC{
char string_buffer[64];
};


struct ABC *DEF(char *name){
name = string_buffer;
};

Upvotes: 2

Views: 1039

Answers (1)

Sourav Ghosh
Sourav Ghosh

Reputation: 134346

string_buffer is not a normal variable. It is a member variable of a variable of type struct ABC. You need to have a variable of type struct ABC and then, you need to access it usig the member access operator (. or ->), like

struct ABC sample = {0};

.... sample.name   //valid access

Also, FWIW, based on your sample code, let me tell you, string_buffer is an array. You cannot assign the array the way you have shown in the sample snippet. In case you want to copy the content, you need to make use of strcpy().

Upvotes: 4

Related Questions