473,394 Members | 1,802 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,394 software developers and data experts.

getting junk value after reading a data from file

1
i am getting junk value in file,if i write a integers to file.can body tell me what's the prob.
Expand|Select|Wrap|Line Numbers
  1. int main ()
  2. {
  3.     FILE*          fp = NULL; 
  4.     UINT32         data[4];
  5.  
  6.     UINT32         i = 0;
  7.     UINT32         res[MAX_SIZE];
  8.     UZN_STATUS       status = UZN_SUCCESS;
  9.     UINT32         count = 0;
  10.     /*Creating file called x*/
  11.  
  12.     memset (data, 0, sizeof(data));
  13.     fp = fopen ("x.bin", "wb");
  14.     data[0]=1;
  15.     data[1]=2;
  16.     data[2]=3;
  17.     data[3]=4;
  18.     if (fp == NULL)
  19.     {
  20.         printf("File open failed\n");
  21.         return -1
  22.     }
  23.  
  24.  
  25.  
  26.          count=fwrite (data, sizeof(UINT32), 1,fp);
  27.         printf("%d", count);
  28.     /*Reading from that same file*/ 
  29.     fread(res,sizeof(UINT32),4,fp)
  30.    for(i=0; i<4; i++)
  31.     {
  32.  
  33.        printf("%8.8x\t",res[i]);
  34.     }
  35.     fclose (fp);
  36. }
May 28 '13 #1
2 2442
Oralloy
988 Expert 512MB
a12b12,

Looks like you forgot to seek to the start of the file before you started reading.

Try looking at this reference on fseek().

Cheers!
Oralloy
May 28 '13 #2
donbock
2,426 Expert 2GB
On line 26 you write one UINT32; but on line 29 you read four UNIT32's.

This is not causing your problem, but it is a good idea for newline ('\n') to be the last character you write to stdout (lines 27 and 33). In some implementations, nothing is visible on stdout until a newline is written.
May 29 '13 #3

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

Similar topics

5
by: risha | last post by:
void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb) { unsigned long ulvald; abb=2; ulvald=0; //fl_ad=(volatile unsigned long *)0x8020; ulvald= *(fl_ad); //return ucVal; }
3
by: Ron | last post by:
I need a way to read the hex values of an old DBase3 data file. Can anyone give me some info regarding how to grab hex values out of a file? Not sure exactly how to do this. Thanks for your...
1
by: Asaf Ganot | last post by:
Hi, I'm looking for a way to retrieve the date type of a registry value using c#. Since I couldn't find a way to do it with 'Microsoft.Win32', I tried to use the good old API call 'RegEnumValue'...
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'?
1
by: Jerry John | last post by:
I am working in ASP.NET with C#. I have a text file which contains datas with delimiters. For example:- MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939| I also have an XML file created...
3
by: Ivan Liu | last post by:
I would like know how I can skip a line while reading a set of input data (from a text file) if the first character of the line is "#". My original code reads: ifstream Infile("data.dat"); ...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
3
kaleeswaran
by: kaleeswaran | last post by:
hi! i am going to display list of 200 titles in my drop down box.it is from data base and show it over the jsp page.so each time i open the page then the drop down box value also loaded again...
6
by: dharanidhar | last post by:
#include<stdio.h> #include<math.h> main() { FILE * fp; struct { int a; float b;
4
by: BibI | last post by:
Hi there, I just started programming with PERL and am trying to put together my first little data manipulation program. I am working on a MAC with OSX. I have a data file with the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.