开发平台(Platform): (Ex: Win10, Linux, ...)
Win7
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
Dev C++
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
stdio.h stdlib.h
问题(Question):
为什么我的switch...case,无法成功加载,会直接跳default:("Error\n);
喂入的资料(Input):
预期的正确结果(Expected Output):
printf("Choice your mode: A.Read B.Write C.Randread D.Randwrite E.Randr
F.RWmixread=70 \n");
scanf("%c", &mode);
输入A.B.C.D.E等,会printf出来结果
错误结果(Wrong Output):
结果直接跳到Error
程式码(Code):(请善用置底文网页, 记得排版)
#include<stdio.h>
#include<stdlib.h>
int main()
{
char filename[10];
int iodepth, bs, size, numjobs, runtime;
printf("Where is your file? (absult postion)\n");
scanf("%s", filename);
printf("Setting your IO module(default=1)\n");
scanf("%d", &iodepth);
printf("What is your I/O size(-bs)?\n");
scanf("%d", &bs);
printf("How much the test file size\n");
scanf("%d", &size);
printf("How many your number of jobs?\n");
scanf("%d", &numjobs);
printf("How long do you wany to test?(sec)\n");
scanf("%d", &runtime);
char mode;
printf("Choice your mode: A.Read B.Write C.Randread D.Randwrite E.Randrw
F.RWmixread=70 \n");
scanf("%c", &mode);
switch(mode)
{
case 'A':
printf("Fuck u\n");
printf("fio -filename=%s -direct=1 -iodepth %d -thread -rw=read
ioengine=libaio -bs=%dm -size=%dG -numjobs=%d -runtime=%d -group_reporting
-name=mytest\n", filename, iodepth, bs, size, numjobs, runtime);
break;
case 'B':
printf("fio -filename=%s -direct=1 -iodepth %d -thread -rw=write
ioengine=libaio -bs=%dm -size=%dG -numjobs=%d -runtime=%d -group_reporting
-name=mytest\n", filename, iodepth, bs, size, numjobs, runtime);
break;
case 'C':
printf("fio -filename=%s -direct=1 -iodepth %d -thread
-rw=randread ioengine=libaio -bs=%dm -size=%dG -numjobs=%d -runtime=%d
-group_reporting -name=mytest\n", filename, iodepth, bs, size, numjobs,
runtime);
break;
case 'D':
printf("fio -filename=%s -direct=1 -iodepth %d -thread
-rw=randwrite ioengine=libaio -bs=%dm -size=%dG -numjobs=%d -runtime=%d
-group_reporting -name=mytest\n", filename, iodepth, bs, size, numjobs,
runtime);
break;
case 'E':
printf("fio -filename=%s -direct=1 -iodepth %d -thread
-rw=randrw ioengine=libaio -bs=%dm -size=%dG -numjobs=%d -runtime=%d
-group_reporting -name=mytest\n", filename, iodepth, bs, size, numjobs,
runtime);
break;
default:
printf("Error\n");
}
return 0;
}
补充说明(Supplement):
作者: stucode 2017-09-08 11:32:00
一时之间想不到用什么关键字可以找到相关问题……也许可以试试scanf input buffer之类的简单来说就是上次输入的时候,例如输入123然后[Enter]输入缓冲区会填入"123\n"。上个scanf只consume掉整数的"123"部分,下一个scanf("%c", ...)读到的就是还留在buffer里面的"\n"。