- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正如你们所看到的,我没有定义变量“n_students”,因此它应该能够毫无问题地递增,但事实并非如此。当我将其放入用户定义函数中时,它也不会增加,那么这里的问题是什么?
#define MAX_CLASS_SIZE 5
#define MAX_NAME_SIZE 11
int main(void){
student_t studentlist[MAX_NAME_SIZE];
int n_students = 0;
int result;
/* TODO */
while (1){
printMenu();
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
if (n_students == MAX_CLASS_SIZE) {
printf("Class is full\n");
}
else {
addStudent(studentlist, n_students);
n_students++;
}
case 2:
if (n_students == 0) {
printf("Class is empty\n");
} else {
n_students--;
}
break;
case 3:
if (n_students == 0){
printf("Class is empty\n");
}
else {
displayStudents(studentlist, n_students);
}
break;
case 4:
saveDatabase(studentlist, n_students);
break;
case 5:
result = loadDatabase(studentlist);
if (result >= 0){
n_students = result;
}
break;
case 6:
return 0;
default:
printf("Invalid choice.\n");
break;
}
}
}
void addStudent(student_t *studentlist,int n_students)
{
char name[1024];
printf("Enter name>");
scanf("%s", name);
name[MAX_NAME_SIZE-1]= '\0';
strcpy(studentlist[n_students].name, name);
int day,month,year;
while (1){
printf("Enter birthday: day>");
scanf("%d", &day);
if (day >= 1 && day <=31){
break;
}
printf("Invalid day. ");
}
while (1){
printf("Enter birthday: month>");
scanf("%d", &month);
if(month >= 1 && month <= 12){
break;
}
printf("Invalid month. ");
}
while (1){
printf("Enter birthday: year>");
scanf("%d", &year);
if (year >= 1800 && year <= 2017){
break;
}
printf("Invalid year. ");
}
float gpa;
while (1){
printf("Enter GPA>");
scanf("%f", &gpa);
if (gpa >= 0.0 && gpa <= 4){
break;
}
printf("Invalid GPA. ");
}
studentlist[n_students].birthday.day = day;
studentlist[n_students].birthday.month = month;
studentlist[n_students].birthday.year = year;
studentlist[n_students].gpa = gpa;
}
最佳答案
首先,您在情况1
之后错过了休息
switch (choice)
{
case 1:
if (n_students == MAX_CLASS_SIZE)
{
printf("Class is full\n");
}
else
{
addStudent(studentlist, n_students);
n_students++;
}
break; <----------------------
case 2:
否则执行情况2
并执行n_students--;
。
此外,您的代码正在检查数组索引 n_stundent
if (n_students == MAX_CLASS_SIZE)
所以数组大小应该是
student_t studentlist[MAX_CLASS_SIZE];
关于c - 尽管 undefined variable 但不增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43799733/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!