使用Run-Time c 函数open的注意事项
来源:互联网 发布:网络电视播放器排行 编辑:程序博客网 时间:2024/05/16 10:21
1.c语言,变量只能在函数开头部分声明,不能在除此之外的任意地方声明。
2.初学者易犯的错误。
int fd;
char file_path[1024];
.....
if ( fd = open(file_path,O_RDONLY ) < 0)
{
goto err;
}
.....
:err
注:无论file_paht为何值,fd = 0!!!!!!!!, 因为 符号 "<"的优先级大于 符号“=",open(file_path,O_RDONLY)<0的表达式值始终为假
正确写法:if ( (fd = open(file_path,O_RDONLY ) ) < 0)
3.
int n_f;
struct stat st;
char buf[1024];
fd = open(file_path, O_RDONLY|O_BINARY);
fstat(fd,&st);
n_f = read(file_paht,buf,st.st_size);
注:只有在open函数中添加O_BINARY选项,read函数才能读出文件的正确大小,否则n_f值小于st.st_size
0 0
- 使用Run-Time c 函数open的注意事项
- 第三篇 使用自己的函数替换C run-time启动函数
- 使用C Run-Time 获取当前进程的路径
- C Run-Time Library的理解
- C Run-Time Library的理解
- C Run-Time Library的理解
- **Objective-C强大的run-time <*******>
- C Run-time library
- C run-time library
- Objective-c Run Time
- C run-time library
- 解决CRT(即C Run-Time)中函数的安全警告
- 一天一个C Run-Time Library 函数(绪)
- 一天一个C Run-Time Library 函数(2) __max & __min
- 一天一个C Run-Time Library 函数(3) abort
- 一天一个C Run-Time Library 函数(4) abs _abs64
- 一天一个C Run-Time Library 函数(5) access
- 一天一个C Run-Time Library 函数(6) 三角函数
- net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
- 解决jni项目编译生成so时报错"argument list too long"
- c语言lesson02
- Linux网络编程必看书籍推荐
- Web Service--java代码实现客户端编写---[小结]
- 使用Run-Time c 函数open的注意事项
- TCP/IP、Http、Socket的区别
- android 矩形碰撞
- shell变量的替换
- 盘点被App Store拒绝的79个原因
- Sun JDK自带JVM内存使用分析工具HProf
- 「leetCode」:Sort List
- 人工智能:互联网巨头全产业扩张的注脚
- 编写一个算法将顺序表A分成两部分,大于0 的在A的左边,小于0的在A的右边