Scanf( )、getchar( )与gets( )函数作为输入函数它们区别是什么?
展开全部
scanf();
输入形式:scanf("%d",&a); scanf("%s",a)(或scanf("%s",&a),不正规);
一一对应:%d int ;%f float ;%lf double ;%ld long ;%I64d __int64 ;%c char ;%s char [] ;
返回值是,输入n个数据,则返回n,无输入,则返回-1,EOF(即end of file),是一个常量-1(可用-1代),操作是用Ctrl+Z。
一条语句可输入多个数据。
默认以空格来跳到下一个输入变量,若完成了本次调用时用户本次规定的输入量,可以缓冲起来,继续输入下一次调用该函数时的数据,发出执行指令后做一起处理。该函数不接收空格,多个空格等同一个空格。可以在一次规定的变量之间加上其他的符号来自定义跳转指令。
若完成了本次规定的输入量,回车表示执行本次要的操作;若未完成本次规定的输入量,则作用同于空格,是跳到下一个输入变量。该函数也不接收回车,多个回车等同一个回车。
故而要注意该函数只能正常接收无空格和字符串,当然含有回车符的字符串也是不行的。
gets();
输入形式:gets(a);(char a[ ]);
输入的对象是字符串,会把一切能接收进来的字符都接收进来(除了回车),如下面代码1中scanf()后面的空格和回车,以回车表示结束该字符串的输入结束。常以防干扰以代码2的形式和scanf();搭配。但是注意一切能接收是指上一个输入变量不要的字符,如上面的空格和回车,但是形如代码3,上一个回车是上一个字符串必要的结尾符,不能给下一个字符接收了。
getchar();
输入字符的函数,一次输入单个字符,可以接收任意形式的字符,可以把它付给一个字符变量,也可以不要接收器。若要用来输入字符串,则可以用EOF来结尾,形式是while((c=getchar())!=EOF)
采纳哦!
输入形式:scanf("%d",&a); scanf("%s",a)(或scanf("%s",&a),不正规);
一一对应:%d int ;%f float ;%lf double ;%ld long ;%I64d __int64 ;%c char ;%s char [] ;
返回值是,输入n个数据,则返回n,无输入,则返回-1,EOF(即end of file),是一个常量-1(可用-1代),操作是用Ctrl+Z。
一条语句可输入多个数据。
默认以空格来跳到下一个输入变量,若完成了本次调用时用户本次规定的输入量,可以缓冲起来,继续输入下一次调用该函数时的数据,发出执行指令后做一起处理。该函数不接收空格,多个空格等同一个空格。可以在一次规定的变量之间加上其他的符号来自定义跳转指令。
若完成了本次规定的输入量,回车表示执行本次要的操作;若未完成本次规定的输入量,则作用同于空格,是跳到下一个输入变量。该函数也不接收回车,多个回车等同一个回车。
故而要注意该函数只能正常接收无空格和字符串,当然含有回车符的字符串也是不行的。
gets();
输入形式:gets(a);(char a[ ]);
输入的对象是字符串,会把一切能接收进来的字符都接收进来(除了回车),如下面代码1中scanf()后面的空格和回车,以回车表示结束该字符串的输入结束。常以防干扰以代码2的形式和scanf();搭配。但是注意一切能接收是指上一个输入变量不要的字符,如上面的空格和回车,但是形如代码3,上一个回车是上一个字符串必要的结尾符,不能给下一个字符接收了。
getchar();
输入字符的函数,一次输入单个字符,可以接收任意形式的字符,可以把它付给一个字符变量,也可以不要接收器。若要用来输入字符串,则可以用EOF来结尾,形式是while((c=getchar())!=EOF)
采纳哦!
展开全部
scanf是格式化输入,可以输入各种各样的东西,但是必须事先指定好将要输入什么,输入顺序等等, 里面要有变量类型和变量名,比如 int a; char b; scanf("%d%c",&a,&b);
%d是整型 %ld是长整型, %c是字符型 %f是浮点型, %s是字符串 字符串的话在后面的变量名前面不用加取地址符&
getchar是输入一个字符,getchar的括号里就写char型的变量名就行了, 比如char a; getchar(a);
gets括号里一般是char型的数组或者指针, gets是连续读入,直到敲回车为止,比如 char a[80]; gets(a);
不会的再问吧
%d是整型 %ld是长整型, %c是字符型 %f是浮点型, %s是字符串 字符串的话在后面的变量名前面不用加取地址符&
getchar是输入一个字符,getchar的括号里就写char型的变量名就行了, 比如char a; getchar(a);
gets括号里一般是char型的数组或者指针, gets是连续读入,直到敲回车为止,比如 char a[80]; gets(a);
不会的再问吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Scanf()输入一个数值
getchar() 输入一个字符
gets()输入一个字符串
我的理解不怎么的全面,
getchar() 输入一个字符
gets()输入一个字符串
我的理解不怎么的全面,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
gets, _getws
Get a line from the stdin stream.
char *gets( char *buffer );
wchar_t *_getws( wchar_t *buffer );
Remarks
The gets function reads a line from the standard input stream
stdin and stores it in buffer. The line consists of all characters
up to and including the first newline character ('\n'). gets then
replaces the newline character with a null character ('\0') before returning the
line. In contrast, the fgets function retains the newline character.
_getws is a wide-character version of gets; its argument and
return value are wide-character strings
getc,
getwc, getchar, getwchar
Read a character from a stream (getc, getwc), or get a
character from stdin (getchar, getwchar
Return Value
Each of these functions returns the character read. To indicate an read error
or end-of-file condition, getc and getchar return EOF, and
getwc and getwchar return WEOF. For getc and
getchar, use ferror or feof to check for an error or for
end of file.
Parameter
stream
Input stream
Remarks
Each of these routines reads a single character from a file at the current
position and increments the associated file pointer (if defined) to point to the
next character. In the case of getc and getwc, the file is
associated with stream (see Choosing Between Functions
and Macros). Routine-specific remarks follow.
Routine
Remarks
getc
Same as fgetc, but implemented as a function and as a
macro.
getwc
Wide-character version of getc. Reads a multibyte
character or a wide character according to whether stream is opened in
text mode or binary mode.
getchar
Same as _fgetchar, but
implemented as a function and as a macro.
getwchar
Wide-character version of getchar. Reads a multibyte
character or a wide character according to whether stream is opened in
text mode or binary mode.
Get a line from the stdin stream.
char *gets( char *buffer );
wchar_t *_getws( wchar_t *buffer );
Remarks
The gets function reads a line from the standard input stream
stdin and stores it in buffer. The line consists of all characters
up to and including the first newline character ('\n'). gets then
replaces the newline character with a null character ('\0') before returning the
line. In contrast, the fgets function retains the newline character.
_getws is a wide-character version of gets; its argument and
return value are wide-character strings
getc,
getwc, getchar, getwchar
Read a character from a stream (getc, getwc), or get a
character from stdin (getchar, getwchar
Return Value
Each of these functions returns the character read. To indicate an read error
or end-of-file condition, getc and getchar return EOF, and
getwc and getwchar return WEOF. For getc and
getchar, use ferror or feof to check for an error or for
end of file.
Parameter
stream
Input stream
Remarks
Each of these routines reads a single character from a file at the current
position and increments the associated file pointer (if defined) to point to the
next character. In the case of getc and getwc, the file is
associated with stream (see Choosing Between Functions
and Macros). Routine-specific remarks follow.
Routine
Remarks
getc
Same as fgetc, but implemented as a function and as a
macro.
getwc
Wide-character version of getc. Reads a multibyte
character or a wide character according to whether stream is opened in
text mode or binary mode.
getchar
Same as _fgetchar, but
implemented as a function and as a macro.
getwchar
Wide-character version of getchar. Reads a multibyte
character or a wide character according to whether stream is opened in
text mode or binary mode.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询