473,414 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how to add a file end of character to a file

23
char * buff
fread(buff,sizeof(char *), 1, fr);
while(!feof(fr))
{
fwrite(buff, sizeof(char *), 1, fw);
fread(buff,sizeof(char *), 1, fr);
}
fread(memblock,sizeof(char), 1, fr);
fwrite(memblock, sizeof(char), 1, fw);

hi this is working in windows
when i am trying to copy in linux..only the end fo file character is unable to copy to the fw. please anyone tell me how to write the eof(fr) to fw.

thanks
Nov 16 '08 #1
4 7851
weaknessforcats
9,208 Expert Mod 8TB
You should not have to actually write and end of file. The end of file marker should be written by fwrite after the data.
Nov 16 '08 #2
Banfa
9,065 Expert Mod 8TB
You should not have to actually write and end of file. The end of file marker should be written by fwrite after the data.
That doesn't quite make sense, how would fwrite know that it was the last call you were going to make to it before calling fclose. But the EOF marker might be put in place as you close the file with fclose.

TBH I thought that EOF markers were a thing of the past (weren't they required by tape drives or something like that) that are not required and rarely used with modern storage media.
Nov 16 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Where's JosAH when you need him?
Nov 17 '08 #4
JosAH
11,448 Expert 8TB
Where's JosAH when you need him?
The saviour is here, fear no more! ;-) End of file characters are coupled to the
stupidity of file systems. Early file systems just knew that a file was store at
secors, say, 5, 9, 24, 42 (in that order) but didn't know for how much that last
sector was filled by the file's data.

The entire last sector was loaded in memory and the user (application) just had
to guess. That's why they came up with a sentinel value, e.g. ^Z to denote the
logical end of file. But what to do if the ^Z value happened to be part of the file
in the last sector? Too bad, the file's length was just a multiple of a sector size.

File systems nowadays do store the exact length of a file so there is no need
anymore to read (or write) those silly sentinel values in the last sector. Deep
down entire sectors are still read but that is way below the application level.

Nowadays people forget to flush buffers (close() does it for them) and expect
reading functions to be psychic, i.e. those functions are expected to predict
whether or not they'll hit an end of file condition at their next read operation.

Because no explicit end-of-file character is being written and because those
single character reading functions have to indicate that they have just bumped
into an end-of-file condition, they have to signal that condition with a sentinel
value again. fgetc() does it by returning -1 which is outside the range of the
valid character values but -1 is not written to a disk file image per se.

kind regards,

Jos
Nov 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: SK | last post by:
Hey folks, I am searching for a string (say "ABC") backwards in a file. First I seek to the end. Then I try to make a check like - do { file.clear (); file.get(c); file.seekg(-2,...
4
by: Gactimus | last post by:
Here is a program that encodes and decodes a text file. What I need to do is write a C++ program that requests 3 different file names. One filename is for the source file to be encoded, another is...
4
by: James Aguilar | last post by:
Hey all, I'm working on an encoding scheme where I am running into a problem with reading a file off a stream. Looking at the binary encoding of the file (using a simple hex editor), there is...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
11
by: MPF | last post by:
Alas, I surrender... In a file from a COBOL dump, which is in ASCII, one of the fields is defined as S9(9) V99 Value +0. The value in this location is 0000018922D, which according to the author...
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
10
by: crystalattice | last post by:
I'm creating an RPG for experience and practice. I've finished a character creation module and I'm trying to figure out how to get the file I/O to work. I've read through the python newsgroup...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.