以下是引用屋顶在2016-4-22 19:21:12的发言:
这两个题目代码怎么编啊,谢谢
这两个题目代码怎么编啊,谢谢
动脑动手,说多无谓,行动最实际。
程序代码:#include <stdio.h>
int main()
{
int i=0, c;
char s[11];
char* p;
p = s;
while(1)
{
c = getchar();
if(c == EOF || i>9)
{
*p = '\0';
break;
}
*p = c;
p++;
i++;
}
printf("%s\n", s);
return 0;
}
[此贴子已经被作者于2016-4-22 22:06编辑过]
程序代码:#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
char str[100];
int i;
printf("输入字符串:\n");
while(gets(str) != NULL && str[0] != '\0')
{
int j=0;
for(i=0;i<strlen(str);i++)
{
if(str[i] == ' ')
continue;
else
str[j++] = str[i];
}
str[j]='\0';
puts(str);
printf("输入下一个字符串(press enter to exit):\n");
}
return 0;
}