#include "pch.h"
#include <iostream>
#include <string.h>
#define SIZE 80
char *s_gets(char*st, int n);
int main()
{
std::cout << "Hello World!\n";
char flower[SIZE];
char addon[] = "s smell like old shoes.";
puts("what is your favorite flower?");
if (s_gets(flower,SIZE))
{
strcat_s(flower, addon);
puts(flower);
puts(addon);
return 0;
getchar();
}
}
char *s_gets(char*st, int n)
{
char *hua;
int i = 0;
hua = fgets(st, n, stdin);
if (hua)
{
while (st[i] != '\n'&&st[i] != '\0')
i++;
if (st[i]=='\n')
{
st[i] = '\0';
}
else
{
while (getchar()!='\n')
{
continue;
}
}
}
return hua;
}
效果图
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019050916440244.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDc4OTYyNA==,size_16,color_FFFFFF,t_70)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)