Home > Back-end >  C (not C, C) members of the struct array pointer assignment problem
C (not C, C) members of the struct array pointer assignment problem

Time:11-11

Typedef struct
{
Char * name;
Char sex;
} Person;

Typedef struct
{
The Person * base;
Int the front;
Int rear;
} SqQueue;

/* this is the definition of structure */

/* below is about the main function of writing */

Void main ()
{
Int e, k, I;
Char * c1 and c2.
SqQueue Mdancers Fdancers;
InitQueue (Mdancers);//men queue initialization
InitQueue (Fdancers);//ms queue initialization
The Person dancer [MAXQSIZE];
Printf (" please input will need a few songs: ");
The scanf (" % d ", & amp; E);
Printf (" please input how many total entry: ");
The scanf (" % d ", & amp; K);
for(i=0; i{
Printf (" please enter the name of the dancer: ");
The scanf (" % s ", & amp; C1);
Printf (" please enter the dancer's gender (F/M) : ");
The scanf (" % s ", & amp; C2);

/* this block for the name of the assignment to assignment up is where there is a problem, can't figure out, save the children */
/*====================================*/
Dancer [I]. Name=c1;
Printf (" % s ", dancer [I] name);
Dancer [I] sex=c2;
/*====================================*/

}
for(i=0; i{
DancePartner (dancer, k, Mdancers Fdancers);
}
system("pause");
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- line -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Hope give us a hand with bosses, thanked you niuniu here

CodePudding user response:

The scanf (" % s ", & amp; C1); This sentence has a problem, c1 is a pointer, you still pick up address, & amp; C is equivalent to a char * * type, can change the scanf (" % s ", c1);

CodePudding user response:

Suggest to look at the knowledge of the pointer (feel these Pointers you define what assignment is a mess is a mess)

CodePudding user response:

reference 1/f, a white steamed bun response:
the scanf (" % s ", & amp; C1); This sentence has a problem, c1 is a pointer, you still pick up address, & amp; C is equivalent to a char * * type, can change the scanf (" % s ", c1);

Feeling more than the problem, he structure inside the name is a pointer, give the name behind the assignment when there are problems (for reference)
  • Related