嘿,我是c编程的新宠...... 我遇到了以下问题...
#include<stdio.h>
main(){
char line[80];
scanf("%[^\n]",line); /*here i say it is terminated when new line encounterd*/
printf("%s",line);
}
此代码用于在一行中获取字符串输入,并强制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);
}
这是另一个只占用空格的代码,&#39; B&#39;&#39; C&#39;&#39; D&#39;
如果我想在整数类型的情况下通过使用我能做什么来完成这项工作?
答案 0 :(得分:0)
试试这个:
#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;
}