与“否定扫描集”相关的问题C程序中的转换规范 [英] Problem related to "negated scanset" conversion specification in C program

查看:75
本文介绍了与“否定扫描集”相关的问题C程序中的转换规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   stdio.h  >  
main()
{
char 地址[ 20 ];
printf( 请输入您的完整住址:\ n);
scanf( %[^ $],& address);
printf( 您的地址是:%s \ n \ n,地址);
getchar();
}





CASE-I:当我完成输入后,无论我按下输入按钮多少次在键盘上,屏幕从不显示输出,而是光标只是继续前进到下一行,即它继续将换行符(\ n)作为输入。

CASE-II :当我在输入后插入(输入)一个$字符(我需要输出)时,然后当我按下'ENTER'时,屏幕上会出现输出。



我理解的是什么?

CASE-II的结果对我来说非常清楚,因为在这种情况下,当scanf遇到'$'字符时,它终止读取输入字符,并且在按ENTER时它会生成输出。



我不明白的是什么?

CASE-II对我来说不清楚。我无法理解发生了什么在这种情况下。



我尝试了什么:



我可以在我的标准教科书中找不到任何理由。解决方案

,& address);
printf( 您的地址是:%s \ n \ n,地址);
getchar();
}





CASE-I:当我完成输入后,无论我按下输入按钮多少次在键盘上,屏幕从不显示输出,而是光标只是继续前进到下一行,即它继续将换行符(\ n)作为输入。

CASE-II :当我在输入后插入(输入)


字符时(我需要输出),然后当我按下'ENTER'时,屏幕上会出现输出。



我的理解是什么?

CASE-II的结果非常清楚,因为在这种情况下,当scanf遇到'


'字符终止读取输入字符,按ENTER键产生输出。



我不明白的是什么?

CASE-II对我来说不清楚。我无法理解这种情况发生了什么。



我尝试了什么:



我不能在我的标准教科书中找到任何理由。


#include<stdio.h>
    main()
    {
    	char address[20];
        printf("Please enter your full residential address :\n");
    	scanf("%[^$]",&address);
        printf("Your address is : %s\n\n",address);
    	getchar();
    }



CASE-I : When i am finished giving the input, then no matter how many times i press enter button on keyboard, the screen never displays the output, instead the cursor just keeps on going to the next line,i.e., it keeps taking the newline character(\n) as an input.
CASE-II : When i insert(input) a $ character after my input(for which i need output), then as i press 'ENTER' output appears on the screen.

What i understand ?
The result of CASE-II is pretty clear to me as in this case when the scanf encounters the '$' character it terminates reading the input characters, and on pressing ENTER it generates the output.

What i don't understand ?
CASE-II is not clear to me.I can't understand what is happening in this case.

What I have tried:

I can't find any reason behind this in my standard textbooks.

解决方案

",&address); printf("Your address is : %s\n\n",address); getchar(); }



CASE-I : When i am finished giving the input, then no matter how many times i press enter button on keyboard, the screen never displays the output, instead the cursor just keeps on going to the next line,i.e., it keeps taking the newline character(\n) as an input.
CASE-II : When i insert(input) a


character after my input(for which i need output), then as i press 'ENTER' output appears on the screen.

What i understand ?
The result of CASE-II is pretty clear to me as in this case when the scanf encounters the '


' character it terminates reading the input characters, and on pressing ENTER it generates the output.

What i don't understand ?
CASE-II is not clear to me.I can't understand what is happening in this case.

What I have tried:

I can't find any reason behind this in my standard textbooks.


这篇关于与“否定扫描集”相关的问题C程序中的转换规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆