1、char *input(char *a)
{
int i=0;
while ((a[i]=getchar())!='\n')
i++;
a[i]='\0';
return a;
}
int output(const char *a)
{
int i;
for (i = 0; a[i]; i++) {
if (putchar(a[i])==EOF) return EOF;
}
putchar('\n');
return i;
}
2、//编写函数output和input,其功能分别于gets和puts相同,函数中用getchar和purchar读入和输出字符
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>//包含getch()函数
//系统的gets()函数没有判断输入字符个数是否超过接收缓冲区buf的大小.
//同样,我们这里也不判断
char *input(char *buf)
{
char c = 0;
char *pSaveWork = buf;
while ( true )
{
fflush(stdin);
c = getch();
扩展资料:
如果没有返回值类型名为"void", 整数类型int 类型返回值为整数类型int,以此类推……
类型名有:void int long float int* long* float* ……
C++中函数的调用:函数必须声明后才可以被调用。调用格式为:函数名(实参)
调用时函数名后的小括号中的实参必须和声明函数时的函数括号中的形参个数相同。
有返回值的函数可以进行计算,也可以做为右值进行赋值。
参考资料来源:百度百科-函数