473,473 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

read and write from a sector

6 New Member
hi

actually i m using absread to read a particular sector but when i write it i m getting some special characters instead of actual data.......

i m writing the data by this command

for (i=0; i<512; i++)
{
ch_out = buf[i];
fprintf(fnew1,"%c",ch_out);
}

so can anybody tell me wat can be the problem..........

is it the format s[pecifier that has to be different........

plz help
Jul 12 '07 #1
3 3700
weaknessforcats
9,208 Recognized Expert Moderator Expert
fprintf() formats your data according to your format string.

Probably you need to use fwrite() instead of fprintf() to avoid the formatting.
Jul 12 '07 #2
aditigupta
6 New Member
ya but by using fwrite will i get the data that was stored initially in that file i.e. in the same format and not binary........
Jul 12 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
(i=0; i<512; i++)
{
ch_out = buf[i];
fprintf(fnew1,"%c",ch_out);
}
I assume ch_out is a char?? and that buf is an array of char??

Otherwise the above loop will not work.

ya but by using fwrite will i get the data that was stored initially in that file i.e. in the same format and not binary........
That's only true if you opened the file in text mode. Text mode does the same thing as your fprintf() loop: It converts everytjhing to a char. Worse, it assumes you know the value will fit in the char. Otherwise, you get rollover and a garbage result.

I say again, use fwrite() and open the file in binary mode. That bypasses the conversion to char and lets you write a swatch of memory directly to the file without formatting.
Jul 15 '07 #4

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

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
0
by: munif | last post by:
i wnat write a C++ program that would read from a CD and display information about files and folders in the given CD In simple words you would be performing a simple (ls -l) or (DIR /S) on the...
4
by: Jerry | last post by:
I am trying to read a physical sector off of the disk (the boot sector for drive C:) from C#. I have no problems doing it from a C/C++ application using the Win32 API CreateFile and ReadFile....
1
by: Shrirang Ballal | last post by:
I am doing a project which requires to read the raw bytes from hard disk. It rrequires to access the partition table and then the individual partitions. I want some material related to these...
2
by: Adelino | last post by:
Is it possible to read/write sectores in any hard drive? I have some examples from the net in vc++ but is there a simple way in c#? Thanks The ideia is to do a disk search of a pattern that...
5
by: Sumana | last post by:
Hi All, We developed our project on VC++.Net console application to create image of disk and to write the image We are having problem with reading and writing the sector beyond 6GB Disk or...
2
by: Noel Mosa | last post by:
Hi, i have a file in memory in a char* string(which i read using buffered ifstreams from c++) and want to write a fake read() function for a C program that usually reads from files. What id...
5
by: Jordi Maycas | last post by:
Could I do something like this with .net 2005? PROGRAM WriteBootSector; VAR DiskSectorsPerTrack, DiskTracksPerHead, DiskHeads : WORD; FUNCTION WriteSector(Sector : WORD; Buffer : POINTER) :...
1
by: georgemocanu | last post by:
Hello I have this xml file : <?xml version="1.0" encoding="utf-8" standalone="no"?> <Root Date="Wednesday, September 05, 2007 9:31 AM"> <customer no="210003" name="ADCON ├95 SRL" address="Av....
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
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
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
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.