Q: 为什么我用 gcc 编译出来的 a.out 不能执行?
我编辑了一个 test.c 并用 gcc 编译, 生成一个 a.out 文件
但是为什么它不能执行?
A: 在 Linux 下执行程序需要指定文件路径。 请试试 ./a.out
这里用 ./ 告诉 shell 要执行的程序在当前目录。
当然如果环境变量 PATH 中包含了路径, 则可以不用这样指定。
可以通过设置用户配置文件改变它。
bsh, ksh, bash:
vi ~/.bashrc
add this line:
PATH=$PATH:.
csh, tcsh:
vi ~/.cshrc
add this line:
setenv PATH $PATH:.
这样下次等录就可以直接执行当前目录的程序了。
-- by Singleboy (孤鹰)
Q: 编程问题: 如何在 Linux 中得到特殊键的扫描码?
在 DOS 下面可以通过 INT86 函数进行系统调用来得到方向键的码。
但是在 UNIX 下用 GCC 的什么函数可以读入方向键,
又是用什么函数来输出一个方向键呢?
A: there is structure kbentry defined in /usr/include/linux/kd.h
and,u can find definitions of the structure’s members in
/usr/include/linux/keyboard.h,
then use ioctrl() to set the keymap,and read() to read the
value retured when a key being pressed.
-- by jbru (无病无灾便是福)
Q: 编程问题: 关于文件结束的判断偶要对一个log文件进行分析,通过下面的方法打开
if ((fp=fopen(free,"r+"))==NULL){ //the free ip file created by manual printf("can’t open file %s.",free);
putchar(’ ’);
exit(0);
}
通过fgets函数从fp流中取出字符串验证,正确!
但当偶用while(fgetc(fp)!=EOF){}进行提取分析时,却发生
"Segmentation fault"错误!
呜呼!为什么?????
A: "Segmentation fault"错误!
~~~~~~~~~~~~~~~~~~~ 这种错误是因为指针为空。
而且用EOF作为文件结束的标志不太好,可能文件结束了还是!=EOF。
Try to use:
while(!feof(fp)) {
fgetc(fp);
}
试试看。