Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17-01-2009
Member
 
Join Date: Dec 2008
Posts: 33
Convert Text File To Binary

hi,

i have small problem in C + + there.

I have a. txt all that is simple and readable format ascii in notepad and I would copy the contents to a binary file (to be called up to win).

I use the following functions:
fread and fwrite for access binary ansi_c fgets, fputs, fgetc, fputc access to text


To read it well be the same thing but in the opposite direction to regenerate the txt file from the binary.

a little help or track?

thank you
Reply With Quote
  #2  
Old 17-01-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Convert Text File To Binary

hi,
use std:: ostream, std:: IStream with good flags.
Reply With Quote
  #3  
Old 17-01-2009
Member
 
Join Date: Dec 2008
Posts: 33
Re: Convert Text File To Binary

I am based on the examples of functions:

Code:
  • int length; char * buffer; ifstream infile ( "D: \ \ test.txt", ifstream:: in); ofstream outfile ( "D: \ \ test.bin", ofstream:: binary); / / Get length of file: infile.seekg (0, ifstream:: end); infile.tellg length = (); infile.seekg (0, ifstream:: beg); / / Allocate memory: buffer = new char [length]; / / Read data as a block: infile.read (buffer, length); infile.close (); / / Write to outfile outfile.write (buffer, length); outfile.close (); delete [] buffer; return 0;
I have the same problem as before the files are readable even under notepad.
Reply With Quote
  #4  
Old 17-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Convert Text File To Binary

This program reads a text file, and outputs a matrix or permutation in internal format depending on the input to BinFile (default: P2). If the input file name is '=', input is read from stdin. If no arguments are given, T1 is used as input file and output goes to P2. Here are some examples:
Command Conversion
zcv T1 -> P2
zcv txt Txt -> P2
zcv txt z1 Txt -> z1
zcv = z1 standard input -> z1

To convert text from a file called `=' you must use input redirection:
zcv = binfile < =
Reply With Quote
  #5  
Old 17-01-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Convert Text File To Binary

It might seem strange to you, but text files are binary, too. It's the application that treats them differently. For example, if you change the extension from .txt to .bin, the application will not handle it the same.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Convert Text File To Binary"
Thread Thread Starter Forum Replies Last Post
binary and text conversion java Ronguor Software Development 1 14-03-2012 01:24 PM
Need help to convert a Text file to Excel via VBA Macro DEvOTeEL MS Office Support 1 24-02-2012 01:47 PM
How to convert image text into a text file Wadee Windows Software 5 02-12-2010 06:33 PM
How to convert text file to CSV Yancy Tips & Tweaks 3 31-07-2009 05:08 PM
Convert Hex Value to Date from Binary Reg Key RobT Windows Server Help 4 01-04-2005 11:55 AM


All times are GMT +5.5. The time now is 07:50 AM.