本帖最后由 baye1992 于 2016-3-11 15:51 编辑
- </blockquote></div><div class="blockcode"><blockquote>#include <stdio.h>
- #include <string.h>
- #define LEN 3
- int main(int argc, const char * argv[]) {
- //设置个字符串数组指针
- char *str[LEN];
- //循环录入字符串
- for (int i = 0; i<LEN; i++) {
- printf("请输入第%d个字符串:\n",i+1);
- gets(&str[i]);
- }
- //循环比较
- for (int i = 0; i<LEN; i++) {
- for (int j = 0; j<LEN-i-1; j++) {
- if (strcmp(&str[j], &str[j+1])>0) {
- char *p = str[j];
- str[j] = str[j+1];
- str[j+1] = p;
- }
- }
- }
-
- //打印字符串
- for (int i = 0; i<LEN; i++) {
- puts(&str[i]);
- }
- printf("\n");
- return 0;
- }
复制代码
求完善~~
因为gets()会有警告,但是把gets()换成fgets()打印结果又是一堆乱码,该怎么弄啊~~?
|
|