各位高手~!~!~!~!帮帮小弟`!~!~!~!~!

sunfengasd 2006-10-05 12:08:14
小弟我正在做一个作业~!~学生管理系统~!~!
做着后面~!需要用文件~语句~可是我还没有学到这,我看了一下书,可是看不明白`!
希望各位高手大哥们详细指导一下`!~!!~!
我的思路是这样:

#include<stdio.h> //主函数的头文件
#include<stdlib.h> //清楚语句的头文件
#include<string.h> //字符窜比较的头文件


void Menu(); //功能菜单函数声明
void Add(); //添加信息函数声明
void Dr(); //登入函数声明



char g_sNewId[20];
char g_sPassword[10];


void main(void) //主函数
{
int nA=0;
printf("-----------学 生 管 理 系 统-----------\n");
printf("1、注册 2、登入\n");
printf("请选择:");
scanf("%d",&nA);
if(nA==1)
{
char cA;
printf("请输入ID(英文字母或中文):");
scanf("%s",g_sNewId);
printf("请输入密码(英文字母或数字):");
scanf("%s",g_sPassword);
printf("注 册 成 功!\n");
printf("是否登入[Y]/[N]:");
scanf("%c",&cA);scanf("%c",&cA);
printf("-----------学 生 管 理 系 统-----------\n");
if(cA=='y'||cA=='Y')
{
system("cls"); //清楚语句
printf("-----------学 生 管 理 系 统-----------\n");
Dr(); //登入函数调用
}

}
else if(nA==2)
{
printf("-----------学 生 管 理 系 统-----------\n");
Dr(); //登入函数调用
}

}

void Dr() //登入函数定义
{
char sId[20];
char sPassword[10];
char cA;
while(1)
{
printf("请输入ID:");
scanf("%s",sId);
printf("请输入密码:");
scanf("%s",sPassword);
if(strcmp(sId,g_sNewId)==0 || strcmp(sPassword,g_sPassword)==0)
{
system("cls");
Menu();break;
}
else
{
printf("您输入的ID或密码错误!\n");
printf("是否重新输入[Y]/[N]:");
scanf("%c",&cA);scanf("%c",&cA);
if(cA=='y'||cA=='Y')
{
continue;
}
else
{
break;
}
}
}
}

void Menu()
{
int nM=0;
printf("-----------学 生 管 理 系 统-----------\n");
printf("请选择:1、添加信息 2、查询信息 3、修改信息 4、删除信息 5、退出\n");
scanf("%d",&nM);
switch(nM)
{
case 1: Add(); break;
/*case 2: break;
case 3: break;
case 4: break;
case 5: break; */
}
}

struct Newinfo
{
int nId;
char cSex; //性别
char string[10];
double dbMark; //成绩
};
Newinfo sun;

void Add()
{
system("cls");
printf("-----------学 生 管 理 系 统-----------\n");
printf("请输入新信息:\n");
printf("ID:");
scanf("%d",&sun.nId);
printf("性别(男-M 女-W):");
scanf("%c",&sun.cSex);
scanf("%c",&sun.cSex);
printf("英文课名:");
scanf("%s",sun.string);
printf("成绩:");
scanf("%lf",&sun.dbMark);

}
...全文
376 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunfengasd 2006-11-07
  • 打赏
  • 举报
回复
不好意思~!~!
光学习了~!~!忘了回帖了
这个问题早都解决了~!~!~!
谢谢大家的帮助~!~!~!
我们先在都学到C++了~!~!~
leonkiros2004 2006-10-18
  • 打赏
  • 举报
回复
printf("请输入ID(英文字母或中文):");
scanf("%s",g_sNewId);
printf("请输入密码(英文字母或数字):");
scanf("%s",g_sPassword);

没有"&"吗?
helanshan 2006-10-11
  • 打赏
  • 举报
回复
建两个结构,一个是用户,一个是学生,分别对应两个文件。。
struct user //用户结构
{
char userID[10];
char password[10];
}users[10];

struct student //学生结构
{
int xuehao;
char name[10];
int age;
}stu[40];
用fread 读文件
用 fwrite 写文件
leonkiros2004 2006-10-11
  • 打赏
  • 举报
回复

这个什么意思啊?
system("cls"); //清楚语句
leonkiros2004 2006-10-11
  • 打赏
  • 举报
回复
/*我是新手*/
问一下,这里为什么要有两个scanf语句啊?起什么作用的啊?
printf("是否登入[Y]/[N]:");
scanf("%c",&cA);scanf("%c",&cA);
飞哥 2006-10-09
  • 打赏
  • 举报
回复
Example

/* FGETS.C: This program uses fgets to display
* a line from a file on the screen.
*/

#include <stdio.h>

void main( void )
{
FILE *stream;
char line[100];

if( (stream = fopen( "fgets.c", "r" )) != NULL )
{
if( fgets( line, 100, stream ) == NULL)
printf( "fgets error\n" );
else
printf( "%s", line);
fclose( stream );
}
}


Output

/* FGETS.C: This program uses fgets to display
飞哥 2006-10-09
  • 打赏
  • 举报
回复
Example

/* FSCANF.C: This program writes formatted
* data to a file. It then uses fscanf to
* read the various data back from the file.
*/

#include <stdio.h>

FILE *stream;

void main( void )
{
long l;
float fp;
char s[81];
char c;

stream = fopen( "fscanf.out", "w+" );
if( stream == NULL )
printf( "The file fscanf.out was not opened\n" );
else
{
fprintf( stream, "%s %ld %f%c", "a-string",
65000, 3.14159, 'x' );

/* Set pointer to beginning of file: */
fseek( stream, 0L, SEEK_SET );

/* Read data back from file: */
fscanf( stream, "%s", s );
fscanf( stream, "%ld", &l );

fscanf( stream, "%f", &fp );
fscanf( stream, "%c", &c );

/* Output data read: */
printf( "%s\n", s );
printf( "%ld\n", l );
printf( "%f\n", fp );
printf( "%c\n", c );

fclose( stream );
}
}


飞哥 2006-10-09
  • 打赏
  • 举报
回复
Example

/* FREAD.C: This program opens a file named FREAD.OUT and
* writes 25 characters to the file. It then tries to open
* FREAD.OUT and read in 25 characters. If the attempt succeeds,
* the program displays the number of actual items read.
*/

#include <stdio.h>

void main( void )
{
FILE *stream;
char list[30];
int i, numread, numwritten;

/* Open file in text mode: */
if( (stream = fopen( "fread.out", "w+t" )) != NULL )
{
for ( i = 0; i < 25; i++ )
list[i] = (char)('z' - i);
/* Write 25 characters to stream */
numwritten = fwrite( list, sizeof( char ), 25, stream );
printf( "Wrote %d items\n", numwritten );
fclose( stream );

}
else
printf( "Problem opening the file\n" );

if( (stream = fopen( "fread.out", "r+t" )) != NULL )
{
/* Attempt to read in 25 characters */
numread = fread( list, sizeof( char ), 25, stream );
printf( "Number of items read = %d\n", numread );
printf( "Contents of buffer = %.25s\n", list );
fclose( stream );
}
else
printf( "File could not be opened\n" );
}

唐巧 2006-10-07
  • 打赏
  • 举报
回复
我想书上已经写得很详细了吧,不知道你看的是哪本书,谭浩强的C语言那本书讲得很清楚,不行看看那本吧。
文件操作很简单的,多看几遍,在这儿我最多也只能把书上的打到这儿来,没有用。

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧