您的位置:首页 > 运维架构 > Linux

Linux 下C编程笔记

2015-12-21 13:36 531 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: