[英]How can i prefixed to take input in an integer type array in c? When i use %[^\n] in case of string input
Hey i am a new bee in c programming.... I have faced the following problem... 嘿,我是C语言编程中的新蜂。...我遇到了以下问题...
#include<stdio.h>
main(){
char line[80];
scanf("%[^\n]",line); /*here i say it is terminated when new line encounterd*/
printf("%s",line);
}
This code work for taking string input in a line and also force scanf to take input with space... 该代码用于在一行中接受字符串输入,并强制scanf以空格进行输入...
#include<stdio.h>
main(){
char line[80];
scanf(" %[ ABCD]",line); /*here i say when program encountered anything without blankspace, A,B,C,D it is terminated*/
printf("%s",line);
}
here an another code which take only blank space and 'A','B','C','D' 这是另一个仅占用空格和'A','B','C','D'的代码
if i want to do this job in case of integer type by using this what can i do? 如果我想通过使用此功能在整数类型的情况下完成这项工作,该怎么办?
try this: 尝试这个:
#include <stdio.h>
int main (void) {
int i;
printf("Please enter a number: ");
scanf("%d",&i); /* Waits for input. */
printf("You entered %d\n",i);
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.