控制台下输入字符串(含空格)

来源:互联网 发布:数据库系统的核心是 编辑:程序博客网 时间:2024/06/05 05:37
 C语言格式(需要首先给定一个很大的char 数组)
#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){printf("Please input string:\n");char s1[20];gets(s1);char *s2 = (char*) malloc(strlen(s1)+1);strcpy(s2,s1);printf("The input  string is %s\n",s2);free(s2);return 0;}


 C++语言格式(利用string 类型存储字符串)

原创粉丝点击