Home > Back-end >  Ask bosses c language
Ask bosses c language

Time:09-23

#include
Struct iform {
Char sub [20].
Char name [20].
Int time;
};
Struct iform s [5]={
{" Math ", "Wang", 60},
{32} "Writing", "Li",,
{" C Language ", "Chang", 48},
{" English ", "Ma", 60},
{32} "Art", "Zhang",
};
Int main (void)
{
int i;
Char a, [20].
The scanf (" % s ", & amp; a);
for(i=0; i<5; I++)
{
If (a==s [I]. Sub)
Printf (" % d % s % s ", & amp; S [I]. Sub, & amp; S [I]. Name, & amp; S [I] time);
If (a==s [I]. Sub)
break;
}
return 0;
}
A c homework, why is it that no matter what the results are lost nothing at all

CodePudding user response:

The scanf (" % s ", & amp; a);=="" here is a character array, need not take address mark
If (a==s [I]. Sub)=="" string can't so direct comparisons, want to use the if (STRCMP (a, s [I]. Sub)==0) such comparisons

CodePudding user response:

Printf (" % d % s % s ", s [I]. Sub, s [I]. Name, s [I] time);
  • Related