Home > Back-end >  A program, could you tell me what is wrong, ask the great spirit. I just started a small white
A program, could you tell me what is wrong, ask the great spirit. I just started a small white

Time:09-25

# include
# include
Struct cl {
Char name [3].
int num;
} client [3].

Void input (struct cl client [], int m)
{
int i;
Printf (" do enter client inf: \ n ");
for(i=0; i{
The scanf (" % s: % d ", client [I]. Name, & amp; The client [I] num);
}
}

Int search (struct cl client [], int a)
{
Int I, n=3;
for(i=0; i{
If (client [I] num==a)
{
return 1;
break; }
The else
return -1;
}
}
Void main ()
{
Int a, x, m=3;
Input (client, m);
Printf (" ent luky num: ");
The scanf (" % d ", & amp; A);

X=search (client, a);
{
If (x<0)
Printf (" \ n ");
The else
Printf (" the lucky one is: % s \ n ", client [x] name);
}
system("pause");
}

CodePudding user response:

The
refer to the original poster lyhlw007 response:
# include
# include
Struct cl {
Char name [3].
int num;
} client [3].

Void input (struct cl client [], int m)
{
int i;
Printf (" do enter client inf: \ n ");
for(i=0; i{
The scanf (" % s: % d ", client [I]. Name, & amp; The client [I] num);
}
}

Int search (struct cl client [], int a)
{
Int I, n=3;
for(i=0; i{
If (client [I] num==a)
{
return 1;
break; }
The else
return -1;
}
}
Void main ()
{
Int a, x, m=3;
Input (client, m);
Printf (" ent luky num: ");
The scanf (" % d ", & amp; A);

X=search (client, a);
{
If (x<0)
Printf (" \ n ");
The else
Printf (" the lucky one is: % s \ n ", client [x] name);
}
system("pause");
}

Remove the inside the scanf that:...

CodePudding user response:

I want to ask is how the program after the operation can not get what I want results? No matter what I input, can't find the number corresponding to the name? Where is wrong? Seek a great god advice ~

CodePudding user response:

Didn't see where the problem, and you want to be with a detailed description of phenomenon, in addition, the suggestion is that you can add print in input, take a look at your input from the keyboard and print out the same thing

CodePudding user response:

refer to the second floor lyhlw007 response:
I want to ask is how the program after the operation can not get what I want results? No matter what I input, can't find the number corresponding to the name? Where is wrong? Ask the great spirit show ~


Inside the scanf input string and number you want to use: break up, but the program that you input: as part of the input string also,,, so there is no num which values, so you can not get the answer you want, of course...

CodePudding user response:


Inside the scanf input string and number you want to use: break up, but the program that you input: as part of the input string also,,, so there is no num which values, so you can not get the answer you want, of course...



How can I solve this problem? Thank you very much!

CodePudding user response:

The
reference 5 floor lyhlw007 response:
inside the scanf input string and number you want to use: break up, but the program that you input: as part of the input string also,,, so there is no num which values, so you can not get the answer you want, of course...



How can I solve this problem? Thank you very much!


Don't have to use: use a space

CodePudding user response:

reference 3/f, 21211321 response:
didn't see where the problem, and you want a detailed description of phenomenon, in addition, the suggestion is that you can add print in input, take a look at your input from the keyboard and print out is not the same things


Thank you very much!

CodePudding user response:

reference 6 buildings 5250 response:
Quote: refer to the fifth floor lyhlw007 reply:


Inside the scanf input string and number you want to use: break up, but the program that you input: as part of the input string also,,, so there is no num which values, so you can not get the answer you want, of course...



How can I solve this problem? Thank you very much!


Just don't have to use: use Spaces



But if you use to do? Have a solution? thank you

CodePudding user response:

You can consider to receive the name and num, don't want to receive two parameter input at a time

CodePudding user response:

refer to the eighth floor lyhlw007 response:
Quote: refer to the sixth floor 5250 response:

Quote: refer to the fifth floor lyhlw007 reply:


Inside the scanf input string and number you want to use: break up, but the program that you input: as part of the input string also,,, so there is no num which values, so you can not get the answer you want, of course...



How can I solve this problem? Thank you very much!


Just don't have to use: use Spaces



Printf (" do enter client inf: \ n ");
For (I=0; i {
int ch;
Char * p=client [I]. Name;
While ((ch=getchar ())!={
':')* p=ch;
p++;
}
The scanf (" % d ", & amp; The client [I] num);

Printf (" % d, % s \ n ", client [I]. Name, client [I] num);
}

It can be


But if you use to do? Have a solution? Thank you

CodePudding user response:

5250 references to the tenth floor response:
Quote: refer to the eighth floor lyhlw007 response:

Quote: refer to the sixth floor 5250 response:

Quote: refer to the fifth floor lyhlw007 reply:


Inside the scanf input string and number you want to use: break up, but the program that you input: as part of the input string also,,, so there is no num which values, so you can not get the answer you want, of course...


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related