- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个小型 DBMS,用于记录学生姓名、 Material #、部门和专业。
我使用文本文件作为数据库;我的程序应该添加新学生、搜索学生、删除学生、更新学生信息等。目前,我正在将学生信息添加到数据库中并且工作正常,但我想要的是不断添加学生而无需再次运行程序,直到我按一个键。
所以,我使用了一个循环(同时执行 while 循环和 while 循环)并且它工作正常,但我无法将它们附加到数据库中。我不知道出了什么问题。
如果我不使用循环,它会将其附加到数据库,但如果我使用循环,它不会附加它。
/*
* Files.c
*
* Created on: Mar 2, 2015
* Author: ousainou
*/
# include <stdio.h>
# include <stdlib.h>
void appending();
void readFile();
main()
{
//printf("do you want to add a student[y/n]");
printf("*********************************\n");
printf("*Students Management System(SMS)*\n");
printf("*********************************\n");
printf("press '1' to add a new student\n");
printf("press '2' to view all students records\n");
//frintf("press '3' to view a a student's information");
//printf("press '4' to edit a student's infomation);
//printf("press '5' to delete a student);
int input;
scanf("%d",&input);
int x= 0;
do{
//do{
if(input == 1)
{
appending();
}
else if(input == 2)
{
readFile();
}
printf("press -1 to exit");
scanf("%d",&input);
if(input == -1)
break;
}while(x == 0);
}
int input;
char firstname[20];
char lastname[20];
char mat_number[10];
char department[10];
char major[20];
char read;
int num = 1;
int count = 0;
void appending()
{
FILE*file = fopen("new file.txt","a");
printf("enter first name\n");
scanf("%s", firstname);
printf("enter second name\n");
scanf("%s", lastname );
printf("enter mat number\n");
scanf("%s", mat_number);
printf("enter department\n");
scanf("%s", department);
printf("enter major\n");
scanf("%s", major);
fprintf(file,"\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n",firstname,lastname,mat_number,department,major);
if(file)
{
printf("%s %s%s",firstname,lastname,"'s information has been stored\n");
}
else
{
printf("database not found ");
}
}
void readFile()
{
FILE*rfile = fopen("new file.txt","r");
if(!rfile)
{
printf("file not found");
exit(-1);
}
else
{
do{
read = fgetc(rfile);
printf("%c",read);
}while(read != EOF);
}
}
最佳答案
您需要关闭文件,一旦打开您可以连续写入,但它不会在您的读取函数上读取新值(因为它作为新文件打开)。阅读后,您可能不需要保持文件打开。使用fclose()
/*
* Files.c
*
* Created on: Mar 2, 2015
* Author: ousainou
*/
# include <stdio.h>
# include <stdlib.h>
void appending();
void readFile();
int main()
{
//printf("do you want to add a student[y/n]");
printf("*********************************\n");
printf("*Students Management System(SMS)*\n");
printf("*********************************\n");
do{
printf("press '1' to add a new student\n");
printf("press '2' to view all students records\n");
printf("press -1 to exit");
//frintf("press '3' to view a a student's information");
//printf("press '4' to edit a student's infomation);
//printf("press '5' to delete a student);
int input;
scanf("%d",&input);
//do{
if(input == 1)
{
appending();
}
else if(input == 2)
{
readFile();
}
else if(input == -1)
{
break;
}
}while(true);
}
int input;
char firstname[20];
char lastname[20];
char mat_number[10];
char department[10];
char major[20];
char read;
int num = 1;
int count = 0;
void appending()
{
FILE* file = fopen("new file.txt","a");
printf("enter first name\n");
scanf("%s", firstname);
printf("enter second name\n");
scanf("%s", lastname );
printf("enter mat number\n");
scanf("%s", mat_number);
printf("enter department\n");
scanf("%s", department);
printf("enter major\n");
scanf("%s", major);
fprintf(file,"\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\n",firstname,lastname,mat_number,department,major);
if(file)
{
printf("%s %s%s",firstname,lastname,"'s information has been stored\n");
fclose(file);
}
else
{
printf("database not found ");
}
}
void readFile()
{
FILE* rfile = fopen("new file.txt","r");
if(!rfile)
{
printf("file not found");
exit(-1);
}
else
{
do{
read = fgetc(rfile);
printf("%c",read);
}while(read != EOF);
fclose(rfile);
}
}
关于c - 学生数据库管理系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28977171/
我们正在开发一个项目,该项目本身就是 CMS 系统,需要处理大量数字数据,如图像、视频和其他 Assets 。我们正在分析使用用 Java 构建的任何第三方 DAMS 系统的选项,因为我们在同一平台上
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
一个简单的问题。 在 magento 中,当转到 System/Configuration 时,左侧导航中有一些主要选项卡。 一般、目录、客户、销售、高级等。 我想知道什么 xml 为那些设置了顺序?
在开发过程中我发现系统配置->设计 HTML Head 部分丢失。 我已经阅读了很多教程,但没有得到这个问题的解决方案。 我已清除缓存并执行索引。 禁用所有安装模块。 我使用的是magento 1.7
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
上下文 我正在遵循 GCP 对 Storing Secrets 的说明在存储桶中。 KMS 用于 file encryption在上传到存储桶之前。 由于数据加密发生在 Google 存储之外,我对
我目前正在为 KMS( key 管理服务)编写云形成模板(CFT),我想向 root 以外的用户授予 key 管理权限和 key 使用权限。我希望通过 CFT 动态调用它。到目前为止,我可以授予 ro
我是一名优秀的程序员,十分优秀!