c - read() not working properly -
i trying read txt file using read() , print out output.
the text file has these numbers:
123 456 227
and code shown below
#include<stdio.h> #include<stdlib.h> #include <fcntl.h> #include<io.h> int main(int argc, char*argv[]){ char* input; char* output; int fd; int temp = 0; if(argc != 3){ printf("too many or few arguments\n"); exit(-1); } input = argv[1]; output = argv[2]; fd = open(input,o_rdonly,0); if(fd == -1){ printf("read failed"); exit(-1); } while(read(fd, &temp ,sizeof(int)) != 0){ printf("%d\n", temp); } close(fd); }
i tried running , output
221458993 909456394 842150410 842150455
what doing wrong?
Comments
Post a Comment