Home > Back-end >  Structure can't follow you, please advise
Structure can't follow you, please advise

Time:09-21

#include
The main () {
Struct bill {
Unsigned char class;
Unsigned char detail;
Float money;
Unsigned char date;
};
Struct bill num [1000]={
"Income", "cost of living", 3000.0, "the 2020-04-01",
"Expenditure" and "lunch", 12.5, "the 2020-04-30,"
"Spending," "books", 25.0, "the 2020-04-30,"
"Spending", "dinner", 16.0, "the 2020-04-30,"
"Income", "cost of living", 3500.0, "the 2020-05-01",
"Spending", "emei mountain tourism", 500.0, "the 2020-05-01"
};
Printf (" % % c c % % 1 f c ", num [2], a class, num [2]. The detail, num. [2] money, num. [2] the date);

}

Why is the typing errors?

CodePudding user response:

This is not done well

CodePudding user response:

reference 1/f, Simple, Soft reply:
this is not done good

?? Why the typing errors

CodePudding user response:

Unsigned char class to unsigned char clazz [256].
Pay attention to the difference between characters and strings, other detail and date is the same problem
In addition, the class the keyword as far as possible not to used for variable

CodePudding user response:

reference qybao reply: 3/f
unsigned char class to unsigned char clazz [256].
Pay attention to the difference between characters and strings, other detail and date is the same problem
In addition, the class the keyword as far as possible not to used for variable

Thank you print it out or not, however, whether the printf to write the wrong

CodePudding user response:

Printf (" % % c c % % 1 f c ") % c to print a single character, % s print string

CodePudding user response:

The
reference 5 floor CHXCHXKKK reply:
printf (" % % % c. The c % 1 f c ") % c to print a single character, % s
print string

Bosses I finished there was a mistake to help me have a look at it in a for loop should be the string in the judgment of the if function?
#include
#include
The main () {
Int I, m;
Float income=0, expend=0, surplus;
Struct bill {
Unsigned char clazz [256].
Unsigned char detail [256].
Float money;
Unsigned char date [256].
};
Struct bill num [1000]={
"Income", "cost of living", 3000.0, "the 2020-04-01",
"Expenditure" and "lunch", 12.5, "the 2020-04-30,"
"Spending," "books", 25.0, "the 2020-04-30,"
"Spending", "dinner", 16.0, "the 2020-04-30,"
"Income", "cost of living", 3500.0, "the 2020-05-01",
"Spending", "emei mountain tourism", 500.0, "the 2020-05-01"
};
Printf (" please enter bills to query number: ");
Scanf_s (" % d ", & amp; I);
For (m=0; M & lt; i; M++) {
If (num [m]. Clazz=="income")
Income + num=[m]. Money;
The else
Expend + num=[m]. Money;
}
Surplus=income - expend;
Categories: number: printf (" % d % s subsidiary: % s compensation: %. The date of 1 f: % s \ n revenue so far: %. Total: 1 f %. 1 f equals: %. 1 f ", I, num [I - 1]. Clazz, num [I - 1]. The detail, num [I - 1]. Money, num [I - 1]. The date, income and expend, surplus);

}

CodePudding user response:

refer to 6th floor ycm151 response:
Quote: refer to the fifth floor CHXCHXKKK reply:

Printf (" % % c c % % 1 f c ") % c to print a single character, % s print string

Bosses I finished there was a mistake to help me have a look at it in a for loop should be the string in the judgment of the if function?
#include
#include
The main () {
Int I, m;
Float income=0, expend=0, surplus;
Struct bill {
Unsigned char clazz [256].
Unsigned char detail [256].
Float money;
Unsigned char date [256].
};
Struct bill num [1000]={
"Income", "cost of living", 3000.0, "the 2020-04-01",
"Expenditure" and "lunch", 12.5, "the 2020-04-30,"
"Spending," "books", 25.0, "the 2020-04-30,"
"Spending", "dinner", 16.0, "the 2020-04-30,"
"Income", "cost of living", 3500.0, "the 2020-05-01",
"Spending", "emei mountain tourism", 500.0, "the 2020-05-01"
};
Printf (" please enter bills to query number: ");
Scanf_s (" % d ", & amp; I);
For (m=0; M & lt; i; M++) {
If (num [m]. Clazz=="income")
Income + num=[m]. Money;
The else
Expend + num=[m]. Money;
}
Surplus=income - expend;
Categories: number: printf (" % d % s subsidiary: % s compensation: %. The date of 1 f: % s \ n revenue so far: %. Total: 1 f %. 1 f equals: %. 1 f ", I, num [I - 1]. Clazz, num [I - 1]. The detail, num [I - 1]. Money, num [I - 1]. The date, income and expend, surplus);

}


If (num [m]. Clazz=="income") this is to use STRNCMP string comparison function, if a different prompt, change their type or the strong around

CodePudding user response:

If (num [m]. Clazz=="income")==="" the if (STRCMP (num [m]. Clazz," income ")==0)
  • Related