473,511 Members | 15,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File management in C

Hi!!!!!!!!!!!
I am a final year engineering student. I am making a final year
project on reed-solomon codec in C using VC++ 6.0. The input to the
program can be any file that the user wants to encode and then later
decode.

This is where I have a problem. I am using fopen, fscanf and fprintf
for input output purposes. I know these are the simple and std means
of doing so. Unfortunately when I run the program the file pointer for
the output stream (sometimes) start printing a few junk characters
(any where in the middle of the file) and then jumps back many places
and starts printing from there. When this error occurs it prints a few
lines and then stops printing completely.

I am NOT USING ANY function in my program that makes the file pointer
jump back.

Can anyone please tell me how I can solve this problem? Your advice
will be highly appreciated. Thank you for your time.

Sincerely,

Ritesh
Nov 14 '05 #1
8 4424
ri************@gmail.com (Ritesh) writes:
[...]
This is where I have a problem. I am using fopen, fscanf and fprintf
for input output purposes. I know these are the simple and std means
of doing so. Unfortunately when I run the program the file pointer for
the output stream (sometimes) start printing a few junk characters
(any where in the middle of the file) and then jumps back many places
and starts printing from there. When this error occurs it prints a few
lines and then stops printing completely.

I am NOT USING ANY function in my program that makes the file pointer
jump back.


What do you mean by "file pointer"?

Do you mean the cursor (on a terminal)? If so, you're probably
printing non-printable characters, including control characters that
cause the cursor to move around.

If you really mean that it's doing the equivalent of fseek(), how do
you know it's doing so? What behavior are you seeing?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #2
On Wed, 06 Apr 2005 01:01:39 -0700, Ritesh wrote:
Hi!!!!!!!!!!!
I am a final year engineering student. I am making a final year
project on reed-solomon codec in C using VC++ 6.0. The input to the
program can be any file that the user wants to encode and then later
decode.
It sounds like your input and possibly output will be general binary data.
This is where I have a problem. I am using fopen, fscanf and fprintf
for input output purposes.
For binary data you would normally use fread() and fwrite(), fscanf() and
fprintf() are really for text data.
I know these are the simple and std means
of doing so. Unfortunately when I run the program the file pointer for
the output stream (sometimes) start printing a few junk characters
(any where in the middle of the file) and then jumps back many places
and starts printing from there. When this error occurs it prints a few
lines and then stops printing completely.
Standard fscanf() and fprintf() functions can't reposition backwards in
the file. Either something else in the program is doing this or you are
misinterpreting what you are seeing.

What is the file format you are producing? If it is basic binary then
"junk characters" aren't an issue because any character is valid. If it
has a specific format and the program is generating incorrect output then
you have a bug in your program. If you want us to help with that you'll
need to show us the code.
I am NOT USING ANY function in my program that makes the file pointer
jump back.


Then you need to do more research into what is actually happening, maybe
reduce the program to something minimal that reproduces the problem. That
might be something you could post.

Lawrence
Nov 14 '05 #3
Ritesh wrote:
Hi!!!!!!!!!!!
I am a final year engineering student. I am making a final year
project on reed-solomon codec in C using VC++ 6.0. The input to the
program can be any file that the user wants to encode and then later
decode.

This is where I have a problem. I am using fopen, fscanf and fprintf
for input output purposes. I know these are the simple and std means
of doing so. Unfortunately when I run the program the file pointer for
the output stream (sometimes) start printing a few junk characters
(any where in the middle of the file) and then jumps back many places
and starts printing from there. When this error occurs it prints a few
lines and then stops printing completely.

I am NOT USING ANY function in my program that makes the file pointer
jump back.

Can anyone please tell me how I can solve this problem? Your advice
will be highly appreciated. Thank you for your time.
Can you recreate the problem with a small piece of code (wholly
contained and compilable) and post it to the newsgroup? Or I'm afraid
that many of the skilfull here will just say there are too many
speculations to just help.

Sincerely,

Ritesh

Nov 14 '05 #4
"Ritesh" swrites:
I am a final year engineering student. I am making a final year
project on reed-solomon codec in C using VC++ 6.0. The input to the
program can be any file that the user wants to encode and then later
decode.


<snip>
"*Any* file" means the file must be opened in binary mode. Is that how you
opened it? It seems a fair guess that you did not.
Nov 14 '05 #5
Ritesh wrote:

I am a final year engineering student. I am making a final year
project on reed-solomon codec in C using VC++ 6.0.
If that matters you are off-topic here. However it is probably
immaterial.
The input to the program can be any file that the user wants to
encode and then later decode.

This is where I have a problem. I am using fopen, fscanf and
fprintf for input output purposes. I know these are the simple and
std means of doing so. Unfortunately when I run the program the
file pointer for the output stream (sometimes) start printing a
few junk characters (any where in the middle of the file) and then
jumps back many places and starts printing from there. When this
error occurs it prints a few lines and then stops printing
completely.

I am NOT USING ANY function in my program that makes the file
pointer jump back.


Yes you are, or it wouldn't be doing it. It smells like a wild
pointer somewhere, or other means of invoking undefined behaviour.
Lacking the source, we can help no further.

You should reduce the program to a minimal compilable unit that
demonstrates the problem. Not over about 100 lines. Publish that
here if you haven't already found your mistake.

Since you are using the broken google interface, pay close
attention to my sig lines, below. Then trim the quotes to the
relevant portion, and do not top-post.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Nov 14 '05 #6
Hi!!!!!!
THANK YOU EVERYONE for making me realize that there is indeed an
problem with my program and not with the file pointers. I am glad to
inform you that I have found the problem and fixed it.

Initially I was opening the file in Binary Mode but the syntax was as
follows:

stream = fopen( "encoded.enc", "r , b" )

With this syntax the compiler was not stating any syntax error but the
file was always opened in Text Mode. Then I changed the syntax as
follows:

stream = fopen( "encoded.enc", "r""b" )

(Note the change from "r , b" to "r" "b" )
Complier accepted this syntax too and this time the file opened in
Binary Mode and the problem was fixed.

Again, Thank you.

Sincerely,

Ritesh
CBFalconer <cb********@yahoo.com> wrote in message news:<42***************@yahoo.com>...
Ritesh wrote:

I am a final year engineering student. I am making a final year
project on reed-solomon codec in C using VC++ 6.0.


If that matters you are off-topic here. However it is probably
immaterial.
The input to the program can be any file that the user wants to
encode and then later decode.

This is where I have a problem. I am using fopen, fscanf and
fprintf for input output purposes. I know these are the simple and
std means of doing so. Unfortunately when I run the program the
file pointer for the output stream (sometimes) start printing a
few junk characters (any where in the middle of the file) and then
jumps back many places and starts printing from there. When this
error occurs it prints a few lines and then stops printing
completely.

I am NOT USING ANY function in my program that makes the file
pointer jump back.


Yes you are, or it wouldn't be doing it. It smells like a wild
pointer somewhere, or other means of invoking undefined behaviour.
Lacking the source, we can help no further.

You should reduce the program to a minimal compilable unit that
demonstrates the problem. Not over about 100 lines. Publish that
here if you haven't already found your mistake.

Since you are using the broken google interface, pay close
attention to my sig lines, below. Then trim the quotes to the
relevant portion, and do not top-post.


Hi!!!!!!
THANK YOU EVERYONE for making me realize that there is indeed an
problem with my program and not with the file pointers. I am glad to
inform you that I have found the problem and fixed it.

Initially I opening the file in Binary Mode but the syntax was as
follows:

stream = fopen( "encoded.enc", "r , b" )

With this syntax the compiler was not stating any syntax error but the
file was always opened in Text Mode. Then I changed the syntax as
follows:

stream = fopen( "encoded.enc", "r""b" )

(Note the change from "r , b" to "r" "b" )
Complier accepted this syntax too and this time the file opened in
Binary Mode and the problem was fixed.

Again, Thank you.

Sincerely,

Ritesh
Nov 14 '05 #7
ri************@gmail.com (Ritesh) writes:
[...]
Initially I was opening the file in Binary Mode but the syntax was as
follows:

stream = fopen( "encoded.enc", "r , b" )

With this syntax the compiler was not stating any syntax error but the
file was always opened in Text Mode. Then I changed the syntax as
follows:

stream = fopen( "encoded.enc", "r""b" )


That will work, but it's an odd way to write it.
"r""b"
is exactly equivalent to
"rb"
which is much clearer. The form you're using is two adjacent string
literals, which are concatenated to together at compilation time to
form a single string "rb".

And please don't top-post. Your response belongs after, or
interspersed with, any quoted text, and you should snip anything
that's not relevant. (For some reason, your response appeared both
before and after the quoted text.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8
On 7 Apr 2005 10:29:20 -0700, in comp.lang.c ,
ri************@gmail.com (Ritesh) wrote:
stream = fopen( "encoded.enc", "r , b" ) stream = fopen( "encoded.enc", "r""b" )


The mode string shold have no spaces or commas. "rb" will work fine.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2120
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
1
2740
by: serge calderara | last post by:
dear all, I have problem accessing section group in my configuration application file. I got an error saying thta I can have only one section ???? here is my application configuration looks...
6
1829
by: Codemonkey | last post by:
Hi, I have a few questions about best practices when it comes to the management of temporary files. Any thoughts anyone can give would be much appreciated. Basically, I'm writing a document...
4
7859
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an...
3
2287
by: kimimaro | last post by:
hi below is my save function that is used to placed data from the C program to a text file for future usage. void save() { FILE *save; int i = 0; save=fopen("employeerecord.txt", "a+");
4
2685
by: Richard | last post by:
Hi all, Is there any class in .NET 1.x that will help me set file & folder permissions for a user? Aka - I would like to do the in code equivalent of right clicking a folder in file explorer...
1
9963
by: PK9 | last post by:
I'm building a windows app using C#. The goal is to merge portions of multiple xml files into one. I currently have an .xsl stylesheet that pulls in the required sections of multiple xml files...
1
1863
by: Anonieko | last post by:
Logging To a File In A S P . N E T 2 . 0 . I also want weekly rolling filename for the log file. Step 1. Create a class library ( 2 classes) ============================== AppWebEvent.cs...
3
8611
by: Freddie | last post by:
hi, i try to get the asp.net 2.0 security controls to work with SQL Server 2005 Dev RTM, this is my connetion string in mashine.config <connectionStrings> <add name="LocalSqlServer"...
0
995
by: Xaradas | last post by:
Hi, I'm writing here to ask if some one know a free software developed with PHP&MySQL for web files management. The basic requirements are: - User Management - File Permission Management...
0
7251
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
7367
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
7430
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...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4743
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...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.