473,770 Members | 5,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Print ( char )10?

Hey, I'm trying to write a file with unix-style newlines (ASCII character 10)
from a c++ program on Windows...it seems that the most straightforward way to
do that is just to print ( char )10, but it seems that when I try to print
that to the file, the program still prints the full CR+LF Windows-style
ending. The code I have looks something like this:

param_file<<"BS EARCH_ALG SIMPLE"<<( char )10;

Is there any way to keep the program (and/or Windows?) from converting my (
char )10 into a CR+LF?

I am writing output that will be input to a program that expects
unix-formatted files.

Cheers,
Joe

Nov 17 '05 #1
4 2291
On Mon, 19 Sep 2005 04:36:03 -0700, jceddy
<jc****@discuss ions.microsoft. com> wrote:
Hey, I'm trying to write a file with unix-style newlines (ASCII character 10)
from a c++ program on Windows...it seems that the most straightforward way to
do that is just to print ( char )10, but it seems that when I try to print
that to the file, the program still prints the full CR+LF Windows-style
ending. The code I have looks something like this:

param_file<<"B SEARCH_ALG SIMPLE"<<( char )10;

Is there any way to keep the program (and/or Windows?) from converting my (
char )10 into a CR+LF?

I am writing output that will be input to a program that expects
unix-formatted files.


You have to open the file in binary mode or call _setmode to suppress the
line terminator translation and Ctrl+Z processing.

P.S. I'd use '\n' instead of (char) 10.

--
Doug Harrison
VC++ MVP
Nov 17 '05 #2
Greetings,

Try using some old C code instead of C++ streams. Try using printf to write
strings of ascii characters to a text file opened using fopen. I don't think
printf does any background "helpful" conversions. Some folks complain that's
what makes old C difficult to use, but it is also what makes it powerful -
plain, simple, straight forward.

Mike

"jceddy" wrote:
Hey, I'm trying to write a file with unix-style newlines (ASCII character 10)
from a c++ program on Windows...it seems that the most straightforward way to
do that is just to print ( char )10, but it seems that when I try to print
that to the file, the program still prints the full CR+LF Windows-style
ending. The code I have looks something like this:

param_file<<"BS EARCH_ALG SIMPLE"<<( char )10;

Is there any way to keep the program (and/or Windows?) from converting my (
char )10 into a CR+LF?

I am writing output that will be input to a program that expects
unix-formatted files.

Cheers,
Joe

Nov 17 '05 #3
mike east wrote:
Greetings,

Try using some old C code instead of C++ streams. Try using printf to write
strings of ascii characters to a text file opened using fopen. I don't think
printf does any background "helpful" conversions. Some folks complain that's
what makes old C difficult to use, but it is also what makes it powerful -
plain, simple, straight forward.


Streams opened in text mode in C (or C++) convert \n to the correct line
terminator for the host platform (CRLF for Windows). Open the file with
"b" in C and with std::binary in C++ to avoid this "background helpful
conversion".

Tom
Nov 17 '05 #4
Thanks, all...I figured out just after posting this that opening the file in
binary mode would do the trick.

Cheers,
Joe

Nov 17 '05 #5

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

Similar topics

5
2273
by: Tristan Miller | last post by:
Greetings. I have an XML file listing various information about text glyphs (Unicode value, HTML entity name, SGML entity name, etc.). All glyphs have a Unicode value, but not all of them have HTML or SGML entity names. I want to print out a list of these glyphs, using the HTML entity name if it is available; otherwise the Unicode value should be printed. The trouble is that I don't know how I can print only one or the other.
29
22578
by: JS | last post by:
I would like to print char 'd': main(){ char g; g = 'a'; g = 'b'; g = 'c'; g = 'd';
2
1702
by: chiara | last post by:
Hi! This is a piece of a code I wrote. It was perfectly working but now it is giving me some problems I can not understand. I scan a directory (ss_data) and I count its alaments. then I print the name of each file in the directory before opening it.Even if the names of the files are stored correctly in the memory the program prints the letter 'E'(the files are named differently, e.g.traind05c1__a.1.1.1.3.fasta). The program correctly...
1
10763
by: Michael Beck | last post by:
I need to select one of about 15 printers, which I have been able to do. Then I need to set that printer as the printer to use, run a Crystal Reports reports, and track if/when the printing job completes. Is there a book or article that can help me? If it is fairly easy, can anyone sen me some code that will get me started. TIA,
3
41946
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned 0x%x\n",(unsigned char)b); }
2
1544
by: tutufan | last post by:
Hi, I'm trying to use template metaprogramming to print (for debugging purposes) the contents of an arbitrary (random-access) container. So, for example, I'd like to be able to print a vector<int>, a vector< vector<double> >, etc., all from the same code. It seems like this is close to a solution, but the g++ doesn't like it (error at bottom). Any suggestions?
5
2696
by: Shraddha | last post by:
Suppose we are having 3 variables...a,b,c And we want to print the permutations of these variables...Such as...abc,acb,bca...all 6 of them... But we are not supposed to do it mannually... I want to know that formula by which this can be possible... Then that program will be ok for nnumber of variables.... Can anyone help me for that?
2
4628
by: laurent.pauloin | last post by:
Hello I have a buffer of char and I want to print in a 64 bit word in hexa. charbuff0 charbuff1 charbuff2 charbuff3 charbuff4 charbuff5 charbuff6 charbuff7 64bit msb 64bit lsb
3
30838
by: Tim | last post by:
Folks, I'm trying to format a print string so that it reports progress whilst processing a looping structure with a date time stamp appended to the end of the string. This started out life as a simple need to create a display that show progress to users when updating large tables in a data warehouse in real time. I have subsequently address that need through a different method, however I am challenged by the seeming impossibility to...
21
2916
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file containing a *single* word made of 25525500 letters and this program works fine on it. I will welcome any suggestions for improvement. /* * A program that will ask the user for input and then will print the words on stdout * and will also...
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.