小编It'*_*Men的帖子

如何将输入文本光标定位在C?

在这里,我有一个非常简单的程序:

 printf("Enter your number in the box below\n");
 scanf("%d",&number);
Run Code Online (Sandbox Code Playgroud)

现在,我希望输出看起来像这样:

 Enter your number in the box below
 +-----------------+
 | |*|             |
 +-----------------+
Run Code Online (Sandbox Code Playgroud)

哪里,|*| 是用户键入其值的闪烁光标.

由于C是一个线性代码,它不会打印盒子艺术,然后要求输出,它将打印顶行和左列,然后输入后打印底行和右列.

所以,我的问题是,我可以先打印盒子,然后有一个功能将光标放回盒子里吗?

c printing output

9
推荐指数
2
解决办法
4万
查看次数

在C中正确比较字符串

我必须创建一个程序,其中输入必须是2个值之一,'M'或'F'.

这是我创建的用于演示的程序段

do
{

     printf("What is your Gender? (M for Male - F for Female) "); 
     fgets(GenderValue, 16, stdin); 

     if (GenderValue[0] == '\n') 
     {
           printf("Try again");
           getch();
           system("cls");
           loop=1;
     }
     else
     {
           loop = -1;
     }
     if (GenderValue == "M");
     {
          loop =-1;
     }
     else if(GenderValue == "F");
     {
          loop=-1;
     }

     else
     {
           printf("Try again");
           getch();
           system("cls");
           loop=1;
     }



 }
 while(loop > 0); //Checks for NULL input

 printf("Gender: %s",GenderValue);
Run Code Online (Sandbox Code Playgroud)

我知道我可以做一个整数选择输入,但如果可能的话我想稍后回收它.

到目前为止,该程序调用我的性别值比较"错误",这很好,除了我不知道下一步该做什么,我可以找到一个比较字符串的函数,但我真的不想让我的代码复杂化.

编辑:复制?,真的吗?,给出的例子甚至没有接近帮助我.

编辑2:发现问题,我有;在我的if语句旁边,现在已修复.但说真的,没有人发现这个?

c string if-statement

0
推荐指数
1
解决办法
223
查看次数

标签 统计

c ×2

if-statement ×1

output ×1

printing ×1

string ×1