linux环境C编程与windows的不同
2015-06-25 22:18
633 查看
1.system("pause")不能使用,可自己写一个mypause()函数
2.system("cls")改用system("clear")
3.不能使用getch不回显字符的函数,只能自己编写函数设置终端参数来实现
4.getchar() 回车键 识别为'\n',值为 10;退格键Backspace识别为delete,值为127
5.windows下目录路径用的是反斜杠 \,linux下是正斜杠 /
6.windows下中文是GBK编码, linux下是utf-8
7.windows下文本文件行尾是\r\n, linux下只有\n
8.fflush不能用于清空stdin,换成__fpurge(stdin),也不是setbuf(stdin, NULL) 这个是关闭缓冲的
#include <stdio.h> #include <stdio_ext.h> void mypause() { char ch; printf("Press Enter to continue...\n"); __fpurge(stdin); while((ch = getchar())!='\n' && ch != EOF) ; }
2.system("cls")改用system("clear")
3.不能使用getch不回显字符的函数,只能自己编写函数设置终端参数来实现
#include <stdio.h> #include <string.h> #include <termios.h> #include <unistd.h> #include <assert.h> char getch(int len_max) { char ch; struct termios old_attr, new_attr; int len = 0; int res = 0; if(len < len_max) { res = tcgetattr(STDIN_FILENO, &old_attr); assert(res == 0); memcpy(&new_attr, &old_attr, sizeof(old_attr)); new_attr.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE); res = tcsetattr(STDIN_FILENO, TCSANOW, &new_attr); ch = getchar(); ++len; res = tcsetattr(STDIN_FILENO, TCSANOW, &old_attr); assert(res == 0); return ch; } else { printf("Your in put must less than %d", len_max); return -1; } }
4.getchar() 回车键 识别为'\n',值为 10;退格键Backspace识别为delete,值为127
5.windows下目录路径用的是反斜杠 \,linux下是正斜杠 /
6.windows下中文是GBK编码, linux下是utf-8
7.windows下文本文件行尾是\r\n, linux下只有\n
8.fflush不能用于清空stdin,换成__fpurge(stdin),也不是setbuf(stdin, NULL) 这个是关闭缓冲的
相关文章推荐
- Linux grub命令
- 手斧Linux – 从LFS到Funtoo (57)
- 手斧Linux – 从LFS到Funtoo (56)
- 手斧Linux – 从LFS到Funtoo (55)
- 手斧Linux – 从LFS到Funtoo (54)
- 手斧Linux – 从LFS到Funtoo (53)
- 虚拟机中Centos7搭建本地仓库
- linux sort 命令详解
- 手斧Linux – 从LFS到Funtoo (52)
- Linux mkdir 命令
- 手斧Linux – 从LFS到Funtoo (51)
- 手斧Linux – 从LFS到Funtoo (50)
- 手斧Linux – 从LFS到Funtoo (49)
- 手斧Linux – 从LFS到Funtoo (48)
- 手斧Linux – 从LFS到Funtoo (47)
- 手斧Linux – 从LFS到Funtoo (46)
- 手斧Linux – 从LFS到Funtoo (45)
- 手斧Linux – 从LFS到Funtoo (44)
- 手斧Linux – 从LFS到Funtoo (43)
- linux程序设计——执行SQL语句(第八章)