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

output error while displaying read file!

25
Hello, the foll pgm displays some wierd looking characters at the output when cout<<buffer<< is done. Pls tell me why it happens and also correct the error.
Thanks,
Prads

Expand|Select|Wrap|Line Numbers
  1. int main () 
  2. {
  3.   int length;
  4.   char * buffer;
  5.   size_t samples_read;
  6.  
  7.   ifstream is; //is is the fid
  8.   is.open ("C:\\t1.txt", ios::binary );
  9.  
  10.   // get length of file:
  11.   is.seekg (0, ios::end);
  12.   length = is.tellg();
  13.   //cout<<"length is"<<length-1<<endl;
  14.   is.seekg (0, ios::beg);
  15.  
  16.   // allocate memory:
  17.   buffer = new char [length];
  18.   //count=is.gcount();
  19.   //cout<<"count is"<<count<<endl;
  20.   // read data as a block:
  21. is.read (buffer,length); //rawsignal is the buffer, length is blksize
  22. //rawsignal=buffer;
  23. //blksize=length;
  24. cout<<"samples read is"<<length-2<<endl;
  25.  
  26.   is.close();
  27. cout<<"file contents"<<buffer<<endl;
  28.   //cout.write (buffer,length);
  29.  
  30.   delete[] buffer;
  31.  
  32.  
  33.  
  34. getchar();
  35. return 0;
  36. }
Nov 3 '07 #1
1 1297
Banfa
9,065 Expert Mod 8TB
Perhaps the original file contains stange data.

Perhaps you should post what you expecting to see and what you did see.
Nov 5 '07 #2

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

Similar topics

6
by: R. Stormo | last post by:
I have a problem showing output that is comming from a script. If I make a script running at commandline it do work and everything are showing. But when I try to execute it from within my proggy...
3
by: Jorge Cecílio | last post by:
Hi! I would like to export some MS-Access reports output to pdf. However, the only possibility offered by Access (afaik) for me to export formatted output is snp (snapshot) (I use MS-Office...
3
by: Blankdraw | last post by:
I'm getting NO errors and 2 warnings with this code. I thought I was ready to write the output-formatting segment, but may be way off the mark now. The warnings say that "OPEN() and READ() are...
2
by: Angel | last post by:
How much harder is it to write data to an XML file instead of an ascii file? When I write an output data file, I usually write it as an ascii file. But the client's been thinking of writing it in...
0
by: Steve Chatham | last post by:
I am stuck on this. It ought to be a simple reason as to why this is problematic, in that it works on smaller groups of data (say under 40 records), but doesn't on larger groups of records (40+)....
25
by: moondaddy | last post by:
I have an application where users need to upload images and in my web.config file I have a setting like this: <httpRuntime maxRequestLength="512" /> Which restricts image larger than 500k from...
37
by: nobody | last post by:
I am writing a framework that other developers will write plug-ins for. I would like for one of the features of the framework to be to intercept all text written to stdout/stderr and prepend...
4
by: ed | last post by:
Hi all, I'm very new to vb (2nd day) and I need to create a small app that will replace my old batch file with a flashy gui. I had some experience with access 2.0 which helps ;) What I would...
19
by: Chad | last post by:
Okay, let's say I have an exotic os that limits how much goes to stdout. When I go like.. #include <stdio.h> int main(void) { int i=0; for(i=0; i< 10; i++) { printf("a \n");
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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.