字符串
#include <stdio.h>#include <ctype.h>
#define SIZE 80
void getword(char *str,int size);
int main(void)
{
char input;
int num = 3;
printf("Please enter the MAX size:");
scanf_s("%d", &num);
printf("Please enter a string:");
gets(input);
getword(input,num);
puts(input);
getchar();
getchar();
return 0;
}
void getword(char *str,int size)
{
char *ch;
ch = str;
while (!isspace(*ch++));
if ((ch - str) > size)
str = '\0';
else
str = '\0';
}
求救一下哪里出错,以编译就不行,在gets那里输入不了字符 本帖最后由 newu 于 2019-6-22 16:43 编辑
在scanf和gets()之间加个getchar(),这样就能过滤掉scanf输入后那个回车
int main(void)
{
char input;
int num = 3;
printf("Please enter the MAX size:");
scanf_s("%d", &num);
getchar();
printf("Please enter a string:");
gets(input);
getword(input,num);
puts(input);
getchar();
getchar();
return 0;
}
这篇文章很清晰:
https://blog.csdn.net/fobdddf/article/details/19479181
页:
[1]