输入一个整型数,然后申请对应大小空间内存,然后读取一个字符串(测试用例的字符串中含有空格),字符串的输入长度小于最初输入的整型数大小,最后输出输入的字符串即可(无需考虑输入的字符串过长,超过了内存大小);
注意下面问题:
char *p;
scanf("%d",&n);
p=malloc(n);
scanf("%c",&c);//注意在scanf和gets中间使用scanf("%c",&c),去除换行
fgets(p,n,stdin);
#include <stdio.h>
#include "stdlib.h"
int main() {
int size;
scanf("%d",&size);
// fflush(stdin); 有些版本不支持
char c;
scanf("%c",&c);// 清除缓冲区
char *p;
p=(char *) malloc(size);
gets(p);
puts(p);
return 0;
}