That is my program that I write with Turbo C. And then I run that program in my SuSe 9. That works absolutely fine except I need to change some #include files. That is not a problem. But when I connect to Unix server by using secure CRT and run on it. It gave me error from I got by errno:Segmentation faultCode:#include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<unistd.h> #include<errno.h> #include<string.h> #include<fcntl.h> int main(int argc, char *argv[]) { // argv[1]="abc.txt"; if(argc!=2) { printf("Usage ./a.out <filename> \n"); return -1; } char filename[20]; strcpy(filename, argv[1]); int fd; fd=open(filename,O_RDONLY); if(fd<0) { printf("error open file"); return -1; } int b=lseek(fd,0,SEEK_SET); if(b!=0) {printf("internal file error"); return -1; } char *c; int d=1; while(d!=0) { int i=0; d=read(fd,c,22); if(d==-1) {printf("file error");int errno;printf("%s",errno);return -1;} if(d!=0) while(d>i) { printf("%c",c[i]); i++; } } close(fd); return 0; }
I am so confused now![]()



LinkBack URL
About LinkBacks



