Home > Back-end >  C language structure
C language structure

Time:10-03

# include
Int mian ()
{
Struct Vistor
{
Char name [10].
int age;
Int pay;
};//define a structure, the member name respectively, and the age, deal with feiyong
Typedef struct Vistor s;//to simplify the structure name for s
S vistor.
Printf (" please input the name of the tourists ");
While (vistor name!='/n')//when visitors name input is n, stop input or input has been
The scanf (" % s ", vistor. Name);
Printf (" the tourists payable to ");
Pay_ment (& amp; Vistor);//structure transfer address function call
return 0;
}
Void pay_ment (s * p)//define a function calculating payable by people of all ages
{
If ((* p). Age> 18)/payment/older than 18, 20
(* p). Pay=20;
The else//less than the free
(* p). Pay=0;
}

The typedef why not change the structure name to s!!!!!!!!!!!

An error as below
| |===build file: "no goals" in "without project" (the compiler: unknown)===|
C: \ Users \ \ Documents \ 86147 elevator program. C | | In the function 'mian: |
C: \ Users \ \ Documents \ 86147 elevator program. 13 C | | warning: multi - character character constant [- Wmultichar] |
C: \ Users \ \ Documents \ 86147 elevator program. 13 C | | warning: comparison between pointer and integer |
C: \ Users \ \ Documents \ 86147 elevator program. 16 C | | warning: implicit declaration of the function 'pay_ment [- Wimplicit - function - declaration] |
C: \ Users \ \ Documents \ 86147 elevator program. | | 19 C error: unknown type name 's' |
| |===build failures: 1 error (s), 3 warning (s) (0, 0 seconds)===|

CodePudding user response:

The
refer to the original poster weixin_46250143 response:
# include
Int mian ()
{
Struct Vistor
{
Char name [10].
int age;
Int pay;
};//define a structure, the member name respectively, and the age, deal with feiyong
Typedef struct Vistor s;//to simplify the structure name for s
S vistor.
Printf (" please input the name of the tourists ");
While (vistor name!='/n')//when visitors name input is n, stop input or input has been
The scanf (" % s ", vistor. Name);
Printf (" the tourists payable to ");
Pay_ment (& amp; Vistor);//structure transfer address function call
return 0;
}
Void pay_ment (s * p)//define a function calculating payable by people of all ages
{
If ((* p). Age> 18)/payment/older than 18, 20
(* p). Pay=20;
The else//less than the free
(* p). Pay=0;
}

The typedef why not change the structure name to s!!!!!!!!!!!

An error as below
| |===build file: "no goals" in "without project" (the compiler: unknown)===|
C: \ Users \ \ Documents \ 86147 elevator program. C | | In the function 'mian: |
C: \ Users \ \ Documents \ 86147 elevator program. 13 C | | warning: multi - character character constant [- Wmultichar] |
C: \ Users \ \ Documents \ 86147 elevator program. 13 C | | warning: comparison between pointer and integer |
C: \ Users \ \ Documents \ 86147 elevator program. 16 C | | warning: implicit declaration of the function 'pay_ment [- Wimplicit - function - declaration] |
C: \ Users \ \ Documents \ 86147 elevator program. | | 19 C error: unknown type name 's' |
| |===build failures: 1 error (s), 3 warning (s) (0, 0 seconds)===|




Define the structure on the outside you defined in the main function structure can only use other function cannot be used in the main function,

Incidentally int mian to int main

CodePudding user response:

Also note that in addition to the first floor said:
While (STRCMP (vistor. Name, "n"))//when visitors name input is n, stop input or input has been
The scanf (" % s ", vistor. Name);

Pay_ment function must be defined before use

Age, in addition, there is no input pay_ment function performs no meaning behind


Basic knowledge is too weak and have a good read

CodePudding user response:

 # include 

Struct Vistor
{
Char name [10].
int age;
Int pay;
};
Typedef struct Vistor s;//to simplify the structure name for s

Void pay_ment * p (s);

//int mian ()
Int main ()
{
S vistor.
Int I;
Printf (" please input the name of the tourists ");
//while (vistor name!='/n')//when visitors name input is n, stop input or input has been
//the scanf (" % s ", vistor. Name);

I=0;
While (I & lt; 10 & amp; & The scanf (" % c ", & amp; Vistor. Name [I]) & amp; & Vistor. Name [I]!='n')
i++;

If (I & lt; 10)
Vistor. Name [I]=0;
The else
Vistor. Name [I - 1]=0;

Vistor. Age=19;
Printf (" the tourists payable to ");
Pay_ment (& amp; Vistor);//structure transfer address function call
Printf (" % s \ n % d % d ", vistor. Name, vistor. Age, vistor. Pay);
return 0;
}
Void pay_ment (s * p)//define a function calculating payable by people of all ages
{
If ((* p). Age> 18)/payment/older than 18, 20
(* p). Pay=20;
The else//less than the free
(* p). Pay=0;
}


For your reference ~

CodePudding user response:

# include
Struct Vistor
{
Char name [10].
int age;
Int pay;
};//define a structure, the member name respectively, and the age, deal with feiyong
Typedef struct Vistor s;//to simplify the structure name for s
Int main ()
{
Void pay_ment (s *);
S vistor.
Do
{
Printf (" please input the name of the visitors \ n ");
The scanf (" % s, % d ", vistor. Name, & amp; Vistor. Age);
printf("\n");
Pay_ment (& amp; Vistor);//structure transfer address function call
}
While (STRCMP (vistor. Name, "n"));//when visitors name input is n, stop input or input has been
return 0;
}
Void pay_ment (s * p)//define a function calculating payable by people of all ages
{
If ((* p). Age> 18)/payment/older than 18, 20
{
(* p). Pay=20;
Printf (" the tourists to cope with 20 yuan ");
}
The else//less than the free
{
(* p). Pay=0;
Printf (" the visitors free \ n ");
}
}


Hey hey, didn't notice which is just begin to write, a lot of problems on the detail, the bug many
This is my new written, compiled no problem, but the vistor. Age when using the scanf assignment, no response
Whatever I input is greater than or less than 18 18, the output is free, what's the problem?

Black window display is that the program is still a little flaw, want to ask what's the problem caused by
Please input the name of the tourists
FGDK, 56

The visitors free
Please input the name of the tourists
nullnullnullnullnullnullnullnull
  • Related