主题:[讨论]求助 求助~~linux文件读写问题
下面这个程序为什么必须定义buff[100]才能正常输出啊~~大于100,小于100都不行啊。还有 memset后就没有输出了。不知道为什么?求助各位高手~~
#include<stdio.h>
#include<unist.h>
#include<sys/type.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
int main()
{
int fd , fd_w , n;
char buff[100];
// memset(buff , 0 , sizeof(buff) );
if((fd=open(“text.c” , O_CREAT | O_RDWR , 0666))<0)
{
Perror(“open error\n”);
Exit(1);
}
if((fd_w=open(“wt” , O_CREAT | O_RDWR | O_TRUNC , 0666))<0)
{
Perror(“open wr error\n”);
Exit(1);
}
if((n=read(fd , buff , strlen(buff)))>0)
printf(“%s\t %d\n”,buff , n);
if(write(fd_w , buff , strlen(buff))>0);
printf(“write :%s”,buff);
close(fd);
close(fd_w);
exit(0);
}
#include<stdio.h>
#include<unist.h>
#include<sys/type.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
int main()
{
int fd , fd_w , n;
char buff[100];
// memset(buff , 0 , sizeof(buff) );
if((fd=open(“text.c” , O_CREAT | O_RDWR , 0666))<0)
{
Perror(“open error\n”);
Exit(1);
}
if((fd_w=open(“wt” , O_CREAT | O_RDWR | O_TRUNC , 0666))<0)
{
Perror(“open wr error\n”);
Exit(1);
}
if((n=read(fd , buff , strlen(buff)))>0)
printf(“%s\t %d\n”,buff , n);
if(write(fd_w , buff , strlen(buff))>0);
printf(“write :%s”,buff);
close(fd);
close(fd_w);
exit(0);
}