|
我刚开始学编程,在读写文件的时候遇到了困难,我的文件可以写,但不可以读,不知道是怎么回事,请高手帮忙
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int fd;
char buf[10];
char data[]="this is a test\n";
if((fd = open("/root/tel.txt",O_RDWR)) == -1)
{
printf("open file error!\n");
exit(-1);
}
else
{
if(write(fd,data,strlen(data)) != strlen(data))
{
printf("write error!\n");
exit(-1);
}
if(read(fd,buf,9) != 9)
{
printf("read error!\n");
exit(-1);
}
buf[9] = 0;
printf("the number of read is %d\n",strlen(buf));
printf("the string of read is %s \n",buf);
}
}
我不知道为什么就是读不出来,我用od看了,写进去了,请高手帮忙看看问题出在哪里?我知道学程序,首先要学调试,但我不知道linux下用什么调试程序,请告诉我一些调试工具,能介绍些用法更好 |
|