Linux 下C编程笔记
2015-12-21 13:36
603 查看
1、源码
#include<stdio.h>
main(){
FILE *fp;
char str[11];
if((fp=fopen("d:\\jrzh\\example\\string","rt"))==NULL){
printf("\nCannot open file strike any key exit!");
getch();
exit(1);
}
fgets(str,11,fp);
printf("\n%s\n",str);
fclose(fp);
}
编译:
[root@localhost C]# gcc -o fgets fgets.c
fgets.c: In function 'main':
fgets.c:8: warning: incompatible implicit declaration of built-in function 'exit'
/tmp/ccmZM2Va.o: In function `main':
fgets.c:(.text+0x40): undefined reference to `getch'
collect2: ld returned 1 exit status
解决办法:
在文件中添加库文件:#include<stdlib.h>
编译: gcc -o fgets fgets.c -I/usr/include -L/usr/lib -lncurses
#include<stdio.h>
main(){
FILE *fp;
char str[11];
if((fp=fopen("d:\\jrzh\\example\\string","rt"))==NULL){
printf("\nCannot open file strike any key exit!");
getch();
exit(1);
}
fgets(str,11,fp);
printf("\n%s\n",str);
fclose(fp);
}
编译:
[root@localhost C]# gcc -o fgets fgets.c
fgets.c: In function 'main':
fgets.c:8: warning: incompatible implicit declaration of built-in function 'exit'
/tmp/ccmZM2Va.o: In function `main':
fgets.c:(.text+0x40): undefined reference to `getch'
collect2: ld returned 1 exit status
解决办法:
在文件中添加库文件:#include<stdlib.h>
编译: gcc -o fgets fgets.c -I/usr/include -L/usr/lib -lncurses
相关文章推荐
- vim 在centos 升级 vim7.3 并且安装gvim
- 为Centos 安装中文
- Vagrant: Failed to mount folders in Linux guest...
- lrzsz常用
- Linux中的syslog 入门学习教程
- linux-->find命令
- linux配置webserver简易步骤
- LINUX 下 配置MySQL数据库集群
- linux命令
- linux-->linux版本详解
- centos设置开机自启动
- linux系统重要目录
- Centos修炼----->Centos7办公环境打造(No2--访问ntfs文件系统)
- Linux 字符设备驱动模型
- linux用户管理及文件权限
- Jenkins进阶系列之——09配置Linux系统ssh免密码登陆
- linux 0.11内核源码 linux下中文注释乱码
- LINUX安装软件
- Linux 系统中匹配文件名大小写的方式很奇怪?
- linux下压缩文件的解压命令