[求助]为什么不能输入字符???
这个主程序里面的scanf好象都没有跳出输入字符的界面,而直接把scanf这一句运行过去。。。。希望大家帮个忙,谢谢!#include "stdio.h"
#include "string.h"
#include "malloc.h"
#include "stdlib.h"
struct hinode hinode[NHINO];
struct dir dir;
struct file sys_ofile[SYSOPENFILE];
struct filsys filsys;
struct pwd pwd[PWDNUM];
struct user user[USERNUM];
FILE *fd;
struct inode *cur_path_inode;
int user_id;
/*kkkkk*/
unsigned short usr_id;
char usr_p[12];
char sel;
char temp_dir[12];
main()
{
unsigned short ab_fd1,ab_fd2,ab_fd3,ab_fd4,i,j;
char *buf,a;
int done=1;
printf("\nDo you want to format the disk or not?\n");
scanf("%s",&a);//为什么运行到这一句时没有跳出让我们输入字符的界面呢?
if(a=='y')
{
printf("\nFormat will erase all context on the disk\n");
printf("Formating...\n");
format();
printf("\nNow will install the fillsystem,please wait...\n");
install();
printf("\n----Login----nPlease input your userid:");
scanf("%u",&usr_id);
printf("\nPlease input your password:");
scanf("%s",&usr_p);
/* printf("nsuccessn");*/
if(!login(usr_id,usr_p))
return;
while(done)
{
printf("\n Please Select Your Operatingn");
printf(" -1----lsn -2----mkdirn -3----change dirn -4----create filen -0----Logoutn");/* 注意*/
sel=getchar();
switch(sel)
{
case 1: /*显示目录内容*/
_ls();
break;
case 2: /*创建目录*/
printf("please input dir name:");
scanf("%s",temp_dir);
mkdir(temp_dir);
break;
case 3: /*改变当前目录*/
printf("please input dir name:");
scanf("%s",temp_dir);
chdir(temp_dir);
break;
case 4: /*创建文件*/
printf("please input file name:");
scanf("%s",temp_dir);
ab_fd1=creat(2118,temp_dir,01777);
buf=(char *)malloc(BLOCKSIZ*6+5);
write(ab_fd1,buf,BLOCKSIZ*6+5);
close(0,ab_fd1);
free(buf);
break;
case 0: /*退出文件系统*/
logout(usr_id);
halt();
done = 0;
default:
printf("error!\nNo such command,please try again.\nOr you can ask your teacher for help.\n");
break;
}
}
}
else
printf("User canselednGood Byen");
}