Hello guys,
Just got a question regarding my program which user inputs a file and I read content inside and create exact copy of file, with the same name.
I have got it working fine for copying the data (content text) along with the filename/filesize before. However I have slight problem
Code:
fdin = open(argv[2].......
fdout=open("copyfile",.....
namelength = strlen(argv[2]);
write (fdout, (unsigned char*)&namelength, sizeof (unsigned char));
write (fdout, argv[2], sizeof(namelength));
int bytesread = read(fdin, buffer, sizeof(buffer)))
write(fdout,bytesread,sizeof(bytesread);
write(fdout,buffer,sizeof(bytesread);
So, say user inputted a file called "hello.txt"-argv[2] and the namelenght variable would be 9 and say if the content data was "This is the file"-(content would be 16 bytes long)
Then the copy file should look like this, just a long string:
9hello.txt16Thisisthefile
Thus I can easily using read() function read the first byte(unsigned char) returning value 9 so I now read the next 9 bytes to get full file name back (hello.txt) then read the next byte being (int type) returning 16 (so I can read next 16 bytes to get content data back)
My problem is the content (data text part 16 bytes) writes ok but all the stuff before (mainly number values) is blank? I understand you cant view integer values something to do with being converted in binary format?
Thanks if any one can help me out