- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,大家好,已经使用这个网站一段时间了,但以前从未发布过(我想这是第一次),无论如何都在做大学作业(制造学位),所以对你们中的一些人来说可能很基础。基本上
问题出在按学生姓名搜索时,程序在底部附近无效,但一旦我输入姓名,程序就会崩溃
任何帮助将不胜感激
#include <stdlib.h>
#include <stdio.h>
#define SIZE 2
struct Student
{
long StudentID;//works
char fname[21];//works
char sname[21];//does not work
int year;//works
char course[51];//works
float results_semester_1[6];//works
float results_semester_2[6];//works
int free; // 1 means its free, 0 means its not
};
struct Student BENG[SIZE];
int menu(); // function prototype
void add_student(); // function prototype
void display_students(); // function prototype
void display_results(); // function prototype
void search_for_student_studentID(); // function prototype
void search_for_student_by_name(); // function prototype
void delete_student(); // function prototype
void initialise_database(); // function prototype
void Run_statistics_for_individual_student(); // function prototype
void Run_statistics_for_all_student(); // function prototype
int linear_search(long); // function prototype
int linear_search_sname(char); // function prototype
int main()
{
initialise_database(); // call the function to set all free positions to 1
for(;;) // infinite loop
{
switch(menu()) // calling function menu within switch
{
case 1:
add_student(); // calling function add_student
break;
case 2:
delete_student(); // calling function delete_student
break;
case 3:
display_students(); // calling function display_students
break;
case 4:
search_for_student_studentID(); // calling function display_students
break;
case 5:
search_for_student_by_name(); // calling function display_students
break;
case 6:
Run_statistics_for_individual_student(); // calling function display_students
break;
case 7:
Run_statistics_for_all_student(); // calling function display_students
break;
case 8:
display_results(); // calling function display_students
break;
case 9:
printf("Quitting Program\n");
exit(1);
default:
printf("Invalid option chosen\n\n");
}
} // end of infinite loop
return 0;
}
void add_student()
{
int freepos = -1, i, j,k,year;
for(i = 0; i < SIZE; i++)
{
if(BENG[i].free == 1)
{
freepos = i;
break;
}
}
if(freepos != -1)
{
do
{
printf("Enter student ID:\n");
scanf("%ld", &BENG[freepos].StudentID);
}
while(BENG[freepos].StudentID<10000000 ||BENG[freepos].StudentID>99999999);
printf("Enter firstname:\n");
scanf("%s", BENG[freepos].fname);
printf("Enter surname:\n");
scanf("%s", BENG[freepos].sname);
do
{
printf("Enter year of course:\n");
scanf("%d", &BENG[freepos].year);
}
while(BENG[freepos].year < 1 || BENG[freepos].year > 4);
printf("Enter course name:\n");
scanf("%s", BENG[freepos].course);
for(j = 0; j < 6; j++)
{
printf("Enter result of semester 1 Module %d:\n", j+1);
scanf("%f", &BENG[freepos].results_semester_1[j]);
}
for(k = 0; k < 6; k++)
{
printf("Enter result of semester 2 Module %d:\n", k+1);
scanf("%f", &BENG[freepos].results_semester_2[k]);
}
BENG[freepos].free = 0; // mark record as taken
}
else
printf("No position free at present\n");
}
void display_students()
{
// output the values just entered
int i, j;
for(i = 0; i < SIZE; i++)
{
if(BENG[i].free == 0) // only print taken records
{
printf("Student ID: %ld:\n", BENG[i].StudentID);
printf("Firstname: %s\n", BENG[i].fname);
printf("Surname: %s\n", BENG[i].sname);
printf("Year: %d\n", BENG[i].year);
printf("Course: %s\n", BENG[i].course);
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[i].results_semester_1[j]);
} // end of for
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[i].results_semester_2[j]);
} // end of for
} // end of if
} // end of for
}
void display_results()
{
// output the values just entered
int i, j;
for(i = 0; i < SIZE; i++)
{
if(BENG[i].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[i].results_semester_1[j]);
} // end of for
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[i].results_semester_2[j]);
} // end of for
} // end of if
} // end of for
}
int menu()
{
int choice;
printf("1. To add a student\n");
printf("2. To delete a student\n");
printf("3. To display all students\n");
printf("4. Find a student using studentID\n");
printf("5. Find a student by student Surname\n");
printf("6. Find student would you like to run statistics for\n");
printf("7. Find statistics for all students\n");
printf("8. Display results of all students\n");
printf("9. Exit Program\n");
do
{
scanf("%d", &choice);
}
while(choice < 1 || choice > 9);
return choice;
}
void initialise_database()
{
int i;
for(i = 0; i < SIZE; i++) // set all structure variables free to 1
BENG[i].free = 1;
}
void delete_student()
{
long search;
int position,freepos;
printf("Enter the number of student to delete\n");
scanf("%ld",&search);
position = linear_search(search);
if ( position == -1 )
printf("%d is not present in array.\n", search);
else
printf("%d is present at location %d.\n", search, position+1);
BENG[position].free = 1;
return;
}
void search_for_student_studentID()
{
long search;
int position,j,i;
printf("Enter the number to search\n");
scanf("%ld",&search);
position = linear_search(search);
if ( position == -1 )
printf("%d is not present in array.\n", search);
else
printf("%d is present at location %d.\n", search, position+1);
printf("Student ID: %ld:\n", BENG[position].StudentID);
printf("Firstname: %s\n", BENG[position].fname);
printf("Surname: %s\n", BENG[position].sname);
printf("Year: %d\n", BENG[position].year);
printf("Course: %s\n", BENG[position].course);
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[i].results_semester_1[j]);
}
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[i].results_semester_2[j]);
}
return;
}
void search_for_student_by_name(sname)
{
int position,j,i;
printf("Enter the surname of student to search\n");
scanf("%s",&sname);
position = linear_search_sname(sname);
if ( position == 1 )
printf("%s is not present in array.\n", sname);
else
printf("%s is present at location %d.\n", sname, position+1);
printf("Student ID: %ld:\n", BENG[position].StudentID);
printf("Firstname: %s\n", BENG[position].fname);
printf("Surname: %s\n", BENG[position].sname);
printf("Year: %d\n", BENG[position].year);
printf("Course: %s\n", BENG[position].course);
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[i].results_semester_1[j]);
}
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[i].results_semester_2[j]);
}
return;
}
int linear_search(long find)
{
int c;
for ( c = 0 ; c < SIZE ; c++ )
{
if (BENG[c].StudentID == find )
{
return c;
break;
}
}
return -1;
}
int linear_search_sname(char find)
{
int c;
for ( c = 0 ; c < SIZE ; c++ )
{
if (BENG[c].sname[21] == find )
{
return c;
break;
}
}
return -1;
}
void Run_statistics_for_individual_student()
{
long search;
int position,j,i,k,r,max,minsums,min=100;
float sums = 0,maxsums=0;
printf("Enter the number to search\n");
scanf("%ld",&search);
printf("The statistics for student ID:\n",search);
position = linear_search(search);
if ( position == -1 )
printf("%d is not present in array.\n", search);
else
for(i = 0; i < 6; i++)
{
sums += BENG[position].results_semester_1[i];
}
printf("Average grade over 6 subjects for this student in semester 1 is %0.2f marks\n", sums/6);
for(i = 0; i < 6; i++)
{
maxsums = BENG[position].results_semester_1[i];
}
if(maxsums>max)
{
max=maxsums;
} // end of if
printf("Max grade for this student in semester 1 is %d\n", max);
{
for(k = 0; k < 6; k++)
{
if(BENG[position].results_semester_1[k]<min)
{
min=BENG[position].results_semester_1[k];
} // end of if
}// end of for
printf("Min grade for this student in semester 2 is %d\n", min);
}
for(i = 0; i < 6; i++)
{
sums += BENG[position].results_semester_2[i];
}
printf("Average grade over 6 subjects for this student in semester 2 is %0.2f marks\n", sums/6);
for(i = 0; i < 6; i++)
{
maxsums = BENG[position].results_semester_2[i];
}
if(maxsums>max)
{
max=maxsums;
} // end of if
printf("Max grade for this student in semester 2 is %d\n", max);
{
for(k = 0; k < 6; k++)
{
if(BENG[position].results_semester_2[k]<min)
{
min=BENG[position].results_semester_2[k];
} // end of if
}// end of for
printf("Min grade for this student in semester 2 is %d\n", min);
}
return ;
}
void Run_statistics_for_all_student()
{
// output the values just entered
int i,j,k, max,min=100;
float sums,maxsums=0;
{
for(i = 0; i < SIZE; i++)
if(BENG[i].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
for(i = 0; i < SIZE; i++)
{
sums += BENG[i].results_semester_1[i];
} // end of for
} // end of for
} // end of if
printf("Average grade for all students in semester 1 is %0.2f \n", sums/(SIZE*6));
}
{
for(k = 0; k < SIZE; k++)
if(BENG[i].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
for(i = 0; i < SIZE; i++)
{
maxsums = BENG[i].results_semester_1[i];
}
if(maxsums>max)
{
max=maxsums;
}
}// end of for
}// end of if
}
printf("Max grade for all student in semester 1 is%d\n", max);
{
for(k = 0; k < SIZE; k++)
if(BENG[k].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
for(i = 0; i < 6; i++)
{
if(BENG[i].results_semester_1[i]<min)
{
min=BENG[i].results_semester_1[i];
}
}// end of for
}// end of for
}// end of if
}
printf("Min grade for all student in semester 1 is %d\n", min);
return ;
}
最佳答案
您的代码中存在大量错误。所有这些都是由于没有放慢速度并思考每条线(以及每条线的一部分)。 C 是一种精确语言。这是它的优势之一。无论是语法还是逻辑,都不存在足够接近的情况。找到大部分...疏忽...的一种方法是在打开警告的情况下进行编译。程序的编译字符串至少应包含 -Wall -Wextra
。例如:
gcc -Wall -Wextra -o student_database student_database.c
这将捕获大部分基本语法和变量类型不匹配问题。消除每一个警告。编译器并没有意外地抛出它们。它们意味着某些东西。
话虽这么说,我已经消除了代码中的警告。我已经使用了 add_student 函数,使其接受输入并防止换行符在下一个条目之前保留在输入缓冲区中。我已经纠正了其他区域,只是为了解决编译器警告。您的代码仍然需要大量工作。这会给你一个良好的开始并消除那种不知所措的感觉(暂时)。检查你的代码,看看我所做的更正。慢点——你会做得很好。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SIZE 4
struct Student
{
long StudentID;//works
char fname[21];//works
char sname[21];//does not work
int year;//works
char course[51];//works
float results_semester_1[6];//works
float results_semester_2[6];//works
int free; // 1 means its free, 0 means its not
};
struct Student BENG[SIZE];
int menu(); // function prototype
void add_student(); // function prototype
void display_students(); // function prototype
void display_results(); // function prototype
void search_for_student_studentID(); // function prototype
void search_for_student_by_name(); // function prototype
void delete_student(); // function prototype
void initialise_database(); // function prototype
void Run_statistics_for_individual_student(); // function prototype
void Run_statistics_for_all_student(); // function prototype
int linear_search(long); // function prototype
int linear_search_sname(char*); // function prototype
int main()
{
initialise_database(); // call the function to set all free positions to 1
for(;;) // infinite loop
{
switch(menu()) // calling function menu within switch
{
case 1:
add_student(); // calling function add_student
break;
case 2:
delete_student(); // calling function delete_student
break;
case 3:
display_students(); // calling function display_students
break;
case 4:
search_for_student_studentID(); // calling function display_students
break;
case 5:
search_for_student_by_name(); // calling function display_students
break;
case 6:
Run_statistics_for_individual_student(); // calling function display_students
break;
case 7:
Run_statistics_for_all_student(); // calling function display_students
break;
case 8:
display_results(); // calling function display_students
break;
case 9:
printf("Quitting Program\n");
exit(1);
default:
printf("Invalid option chosen\n\n");
}
} // end of infinite loop
return 0;
}
void add_student()
{
int freepos = -1;
int i = 0;
int j = 0;
int k = 0;
for(i = 0; i < SIZE; i++)
{
if(BENG[i].free == 1)
{
freepos = i;
break;
}
}
if(freepos != -1)
{
do
{
printf("Enter student ID (8-digits): ");
scanf("%ld%*c", &BENG[freepos].StudentID);
}
while(BENG[freepos].StudentID<10000000 || BENG[freepos].StudentID>99999999);
printf("Enter firstname: ");
scanf("%[^\n]%*c", BENG[freepos].fname);
printf("Enter surname: ");
scanf("%[^\n]%*c", BENG[freepos].sname);
do
{
printf("Enter year of course (1-4): ");
scanf("%d%*c", &BENG[freepos].year);
}
while(BENG[freepos].year < 1 || BENG[freepos].year > 4);
printf("Enter course name: ");
scanf("%[^\n]%*c", BENG[freepos].course);
for(j = 0; j < 6; j++)
{
printf("Enter result of semester 1 Module %d: ", j+1);
scanf("%f%*c", &BENG[freepos].results_semester_1[j]);
}
for(k = 0; k < 6; k++)
{
printf("Enter result of semester 2 Module %d: ", k+1);
scanf("%f%*c", &BENG[freepos].results_semester_2[k]);
}
BENG[freepos].free = 0; // mark record as taken
}
else
printf("No position free at present\n");
}
void display_students()
{
// output the values just entered
int i, j;
for(i = 0; i < SIZE; i++)
{
if(BENG[i].free == 0) // only print taken records
{
printf("Student ID: %ld:\n", BENG[i].StudentID);
printf("Firstname: %s\n", BENG[i].fname);
printf("Surname: %s\n", BENG[i].sname);
printf("Year: %d\n", BENG[i].year);
printf("Course: %s\n", BENG[i].course);
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[i].results_semester_1[j]);
} // end of for
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[i].results_semester_2[j]);
} // end of for
} // end of if
} // end of for
}
void display_results()
{
// output the values just entered
int i, j;
for(i = 0; i < SIZE; i++)
{
if(BENG[i].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[i].results_semester_1[j]);
} // end of for
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[i].results_semester_2[j]);
} // end of for
} // end of if
} // end of for
}
int menu()
{
int choice;
printf("1. To add a student\n");
printf("2. To delete a student\n");
printf("3. To display all students\n");
printf("4. Find a student using studentID\n");
printf("5. Find a student by student Surname\n");
printf("6. Find student would you like to run statistics for\n");
printf("7. Find statistics for all students\n");
printf("8. Display results of all students\n");
printf("9. Exit Program\n");
do
{
scanf("%d", &choice);
}
while(choice < 1 || choice > 9);
return choice;
}
void initialise_database()
{
int i;
for(i = 0; i < SIZE; i++) // set all structure variables free to 1
BENG[i].free = 1;
}
void delete_student()
{
long search = 0;
int position = 0;
printf("Enter the number of student to delete\n");
scanf("%ld%*c",&search);
position = linear_search(search);
if ( position == -1 )
printf("%ld is not present in array.\n", search);
else
printf("%ld is present at location %d.\n", search, position+1);
BENG[position].free = 1;
return;
}
void search_for_student_studentID()
{
long search = 0;
int position = 0;
int j = 0;
printf ("Enter the number to search: ");
scanf ("%ld%*c",&search);
position = linear_search (search);
if ( position == -1 )
printf("%ld is not present in array.\n", search);
else
printf("%ld is present at location %d.\n", search, position+1);
printf("Student ID: %ld:\n", BENG[position].StudentID);
printf("Firstname: %s\n", BENG[position].fname);
printf("Surname: %s\n", BENG[position].sname);
printf("Year: %d\n", BENG[position].year);
printf("Course: %s\n", BENG[position].course);
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[position].results_semester_1[j]);
}
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[position].results_semester_2[j]);
}
return;
}
void search_for_student_by_name (char *sname)
{
int position = 0;
int j = 0;
printf("Enter the surname of student to search\n");
scanf("%[^\n]%*c", sname);
position = linear_search_sname(sname);
if ( position == 1 )
printf("%s is not present in array.\n", sname);
else
printf("%s is present at location %d.\n", sname, position+1);
printf("Student ID: %ld:\n", BENG[position].StudentID);
printf("Firstname: %s\n", BENG[position].fname);
printf("Surname: %s\n", BENG[position].sname);
printf("Year: %d\n", BENG[position].year);
printf("Course: %s\n", BENG[position].course);
for(j = 0; j < 6; j++)
{
printf("Result semester 1 Module %d: %0.2f\n", j+1, BENG[position].results_semester_1[j]);
}
for(j = 0; j < 6; j++)
{
printf("Result semester 2 Module %d: %0.2f\n", j+1, BENG[position].results_semester_2[j]);
}
return;
}
int linear_search(long find)
{
int c = 0;
for ( c = 0 ; c < SIZE ; c++ )
if (BENG[c].StudentID == find )
return c;
return -1;
}
int linear_search_sname(char *find)
{
int c = 0;
for ( c = 0 ; c < SIZE ; c++ )
if (strcmp (BENG[c].sname, find) == 0 )
return c;
return -1;
}
void Run_statistics_for_individual_student()
{
long search = 0;
int position = 0;
int i = 0;
int k = 0;
int max = 0;
int min = 100;
float sums = 0,maxsums=0;
printf("Enter the number to search\n");
scanf("%ld",&search);
printf("The statistics for student ID (%ld):\n",search);
position = linear_search(search);
if ( position == -1 )
printf("%ld is not present in array.\n", search);
else
for(i = 0; i < 6; i++)
{
sums += BENG[position].results_semester_1[i];
}
printf("Average grade over 6 subjects for this student in semester 1 is %0.2f marks\n", sums/6);
for(i = 0; i < 6; i++)
{
maxsums = BENG[position].results_semester_1[i];
}
if(maxsums>max)
{
max=maxsums;
} // end of if
printf("Max grade for this student in semester 1 is %d\n", max);
{
for(k = 0; k < 6; k++)
{
if(BENG[position].results_semester_1[k]<min)
{
min=BENG[position].results_semester_1[k];
} // end of if
}// end of for
printf("Min grade for this student in semester 2 is %d\n", min);
}
for(i = 0; i < 6; i++)
{
sums += BENG[position].results_semester_2[i];
}
printf("Average grade over 6 subjects for this student in semester 2 is %0.2f marks\n", sums/6);
for(i = 0; i < 6; i++)
{
maxsums = BENG[position].results_semester_2[i];
}
if(maxsums>max)
{
max=maxsums;
} // end of if
printf("Max grade for this student in semester 2 is %d\n", max);
{
for(k = 0; k < 6; k++)
{
if(BENG[position].results_semester_2[k]<min)
{
min=BENG[position].results_semester_2[k];
} // end of if
}// end of for
printf("Min grade for this student in semester 2 is %d\n", min);
}
return ;
}
void Run_statistics_for_all_student()
{
// output the values just entered
int i,j,k, max,min=100;
float sums,maxsums=0;
{
for(i = 0; i < SIZE; i++)
if(BENG[i].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
for(i = 0; i < SIZE; i++)
{
sums += BENG[i].results_semester_1[i];
} // end of for
} // end of for
} // end of if
printf("Average grade for all students in semester 1 is %0.2f \n", sums/(SIZE*6));
}
{
for(k = 0; k < SIZE; k++)
if(BENG[i].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
for(i = 0; i < SIZE; i++)
{
maxsums = BENG[i].results_semester_1[i];
}
if(maxsums>max)
{
max=maxsums;
}
}// end of for
}// end of if
}
printf("Max grade for all student in semester 1 is%d\n", max);
{
for(k = 0; k < SIZE; k++)
if(BENG[k].free == 0) // only print taken records
{
for(j = 0; j < 6; j++)
{
for(i = 0; i < 6; i++)
{
if(BENG[i].results_semester_1[i]<min)
{
min=BENG[i].results_semester_1[i];
}
}// end of for
}// end of for
}// end of if
}
printf("Min grade for all student in semester 1 is %d\n", min);
return ;
}
使用/输出:
./bin/student_database
1. To add a student
2. To delete a student
3. To display all students
4. Find a student using studentID
5. Find a student by student Surname
6. Find student would you like to run statistics for
7. Find statistics for all students
8. Display results of all students
9. Exit Program
1
Enter student ID (8-digits): 12345678
Enter firstname: Johnny
Enter surname: Walker
Enter year of course (1-4): 1
Enter course name: UnderwaterMusic
Enter result of semester 1 Module 1: 88.8
Enter result of semester 1 Module 2: 89.8
Enter result of semester 1 Module 3: 90.8
Enter result of semester 1 Module 4: 91.0
Enter result of semester 1 Module 5: 68.7
Enter result of semester 1 Module 6: 66.7
Enter result of semester 2 Module 1: 92.4
Enter result of semester 2 Module 2: 88.4
Enter result of semester 2 Module 3: 82.3
Enter result of semester 2 Module 4: 95.3
Enter result of semester 2 Module 5: 91.2
Enter result of semester 2 Module 6: 88.5
1. To add a student
2. To delete a student
3. To display all students
4. Find a student using studentID
5. Find a student by student Surname
6. Find student would you like to run statistics for
7. Find statistics for all students
8. Display results of all students
9. Exit Program
3
Student ID: 12345678:
Firstname: Johnny
Surname: Walker
Year: 1
Course: UnderwaterMusic
Result semester 1 Module 1: 88.80
Result semester 1 Module 2: 89.80
Result semester 1 Module 3: 90.80
Result semester 1 Module 4: 91.00
Result semester 1 Module 5: 68.70
Result semester 1 Module 6: 66.70
Result semester 2 Module 1: 92.40
Result semester 2 Module 2: 88.40
Result semester 2 Module 3: 82.30
Result semester 2 Module 4: 95.30
Result semester 2 Module 5: 91.20
Result semester 2 Module 6: 88.50
1. To add a student
2. To delete a student
3. To display all students
4. Find a student using studentID
5. Find a student by student Surname
6. Find student would you like to run statistics for
7. Find statistics for all students
8. Display results of all students
9. Exit Program
9
Quitting Program
其他建议
我给您的一个建议是不要在函数中静态声明字符串大小,而只需在 add_student
函数中根据需要进行分配。例如:
struct Student
{
long StudentID;//works
char *fname;//works
char *sname;//does not work
int year;//works
char *course;//works
float results_semester_1[6];//works
float results_semester_2[6];//works
int free; // 1 means its free, 0 means its not
};
然后您可以简单地允许 scanf
根据需要动态分配内存,例如:
scanf("%m[^\n]%*c", &BENG[freepos].fname);
此外,您会看到我必须更改 add_student
中的所有 scanf
格式字符串,以防止 newline
保留在输入缓冲区中(按 [enter] 的结果)导致程序跳过下一个输入。控制输入缓冲区的状态至关重要。有很多方法可以做到这一点,但仔细看看 man scanf
是一个很好的起点。
关于c - 请帮助真正陷入结构困境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27324819/
我正在使用 OneWayToSource绑定(bind),它似乎总是将我的源属性设置为空。为什么呢?这给我带来了麻烦,因为我需要源属性中目标属性的值而不是空值。 这是我的代码: MyViewModel
我有一个实例变量属性,它被声明和实例化,如下所示: $self->{properties}{$key1} = $value; 我的理解是这将声明属性字段,并将其设置为包含一个键值对的哈希原语。 我正
我正在尝试检查给定的数字是否是质数。首先采用试分割法。但该程序的行为很奇怪。这是我使用的。 int no; no = Integer.parseInt(jTextField1.getText());
我正在使用 NSUserDefaults使一个对象在多个 UIViewController 之间保持同步UITabbarController 中使用的 s .为此,我正在实现以下 - (void)vi
考虑以下 Java 方法: public Boolean compare(String val1, String val2) { return val1.length() > 0 && val
我有一个问题...假设我有一个包含城市名称的表。像这样: id name 1 Los Angeles 2 Madrid 我有一张用户表: uid username locationid
我无法理解这个问题。该代码非常基本,但它的行为却出乎意料。该代码是例程的简化版本,用于从每日数据库中提取每月第 15 天的数据并将其保存到单独的文件中。哪里有问题 ?第一个 cout 打印输入外部 i
我在 中使用大背景标签,我想制作一个宽度为 960px 的容器 div。我希望容器 div 位于从顶部向下 15px 的位置,我想我必须使用 position:absolute。我的困境是;容器内的
我遇到了一个难题。我有一个 hashedX 字段,它是一个散列值/加盐值,按照惯例,加盐值保存在 mysql 数据库的同一行中。 hashedX saltX ------ ---
类 java.io.Reader 和 java.io.InputStreamReader 都有具有完全相同签名的读取方法 public int read(char[] charbuf, int off
我有一个包含多个 C# 项目的 C# 解决方案。我打算在其中添加日志记录。此日志记录应该在所有项目中可用,并且最好使用带有滚动文件日志的 log4Net。 在上述前提下,我可以想到两种方法。 在解决方
我开始学习Python,目前我非常喜欢它。但是,如果你能帮我回答几个问题,这些问题一直困扰着我,我找不到任何明确的答案: 就语言兼容性而言,Python 的 C 实现(来自 python.org 的主
我正在尝试使用 AVAssetWriter 将 CGImages 写入文件以从图像创建视频。 我已经让它在模拟器上以三种不同的方式成功运行,但在运行 iOS 4.3 的 iPhone 4 上,每种方法
我需要对一个想法进行建模,可以将其分解并考虑如下: 图书详细信息 图书价格 这里的问题是您可以为书籍设置许多价格,并且这些价格可能会发生变化。这是一个例子 图书详细信息: --------------
我有一个表,其中的行包含名为 MySubId 的列。此列中的值可以重复。我想找到 MySubId 值和出现次数最多的 MySubId 值的行数。 我有以下查询: SELECT MySubId, COU
我有两个具有多对多关系的类,因此我在它们之间创建了一个联接表(一个非常经典的示例!) 在java+hibernate中我想知道哪种方式更好?使用hibernate多对多注释在这两个类之间有多对多关系吗
我正在尝试创建一个 Android 应用程序来完成以下任务:它通过短信向一组收件人(存储在数组中的数字)发送初始调查问题。然后,对于收到的每个响应,它都会向该参与者发送该系列中的下一个问题。这是我做过
这里有一个关于 IncludeEventHandler 的有趣问题。 我正在开发一个基于 Spring 的应用程序,该应用程序使用具有单独投资组合站点的不同供应商的速度。我让供应商通过向他们提供存储在
我真的无法理解事件和委托(delegate)的概念。我知道委托(delegate)是持有方法引用的对象,可以调用具有相同返回类型和参数的方法,但事件到底是什么? 如果我需要使用事件来制作一个简单的计算
在我正在处理的一个项目中,我有一个扩展 JFrame 的主类(名为 TrackWin)。在此框架中,我使用 JTabbedPane。 用户可以从菜单栏在 Pane 中创建新选项卡。每当发生这种情况时,
我是一名优秀的程序员,十分优秀!