王道oj/problem12(动态申请内存存储数组)


网址:http://oj.lgwenda.com/problem/12

思路:用输入的整型创建对应数组,用scanf消除换行键;

          用gets()输入语句并输出,再释放。

代码:

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
int main()
{
int n;
char c;
scanf("%d", &n);
char* p;
p = (char*)malloc(n);
scanf("%c", &c);
gets(p);
puts(p);
free(p);
p = NULL;
return 0;
}

相关