我想从用户那里得到输入,跳过空格,但由于某种原因,这段代码似乎不起作用!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 50
char *gettline();
int main()
{
char *input;
for( ; ; )
{/*here i try to check the input and output*/
printf("#");
input = gettline();
printf("%s\n",input);
free(input);
}
return 0;
}
char *gettline(){
int c,i;
char *input = malloc(sizeof(char)*MAX);
while((input[0]=c=getchar())==' ' || c=='\t'))
;
input[1]='\0';
i=0;
while((c=getchar()) != EOF || c!='\n')
input[i++] = c;
input[i]='\0';
return input;
}
输出打印'#'并获取我的字符串,但是,
由于某种原因,输出不会从输入打印字符串......任何帮助都会很棒!
提前致谢