I have a quick question regarding printing string constants. When you
printf() a string constant, how are the characters encoded that get
sent to the standard output? Is it in the execution character set?
Thanks in advance. 5 1759
On 30 Jun 2006 07:41:14 -0700, "Ross" <ro************ @yahoo.co.uk>
wrote: I have a quick question regarding printing string constants. When you printf() a string constant, how are the characters encoded that get sent to the standard output? Is it in the execution character set?
If by string constant you mean string literal, they are created at
compile time. I expect the compiler is required to convert them from
the compilation character set to the execution character set. On the
other hand, you can send any NUL-terminated array of char to printf
and it is up to whatever is on the other side of stdout to determine
what happens to each byte.
Remove del for email
"Ross" <ro************ @yahoo.co.uk> wrote I have a quick question regarding printing string constants. When you printf() a string constant, how are the characters encoded that get sent to the standard output? Is it in the execution character set?
That's right.
Normally C source is written in ASCII, and generally C programs use ASCII
internally as their execution set. A few years ago I would have said "most
machines are ASCII" but the concept of an "ASCII machine" has become a bit
fuzzier since then.
Occasionally you might have a C source, but compile for a machine with a
funny character set. So the source file
printf("Hello world\n");
contains the ASCII values 72, 101, 108, 108, etc, along with ASCII values
for the quote,34 paretheses 40, 41, and so on.
Our funny system uses 100 for A, 101 for B, 200 for a 201 for b and so on.
So when we compile, the string "Hello world\n" is laid out in memory as 107,
204, 211, 211 etc. These values are passed to printf(), and by some magic
the glyphs appear in shining pixels on the screen.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
"Malcolm" <re*******@btin ternet.com> writes: "Ross" <ro************ @yahoo.co.uk> wroteI have a quick question regarding printing string constants. When you printf() a string constant, how are the characters encoded that get sent to the standard output? Is it in the execution character set? That's right. Normally C source is written in ASCII, and generally C programs use ASCII internally as their execution set. A few years ago I would have said "most machines are ASCII" but the concept of an "ASCII machine" has become a bit fuzzier since then.
[...]
It depends on what you mean by "normally".
There are still machines that use the EBCDIC character set. C
programs on such machines are written in EBCDIC, and they generally
produce EBCDIC output. This is not common, and it's probably becoming
less common with the passage of years, but there's nothing abnormal
about it.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Keith Thompson" <ks***@mib.orgw rote
"Malcolm" <re*******@btin ternet.comwrite s:
It depends on what you mean by "normally".
There are still machines that use the EBCDIC character set. C
programs on such machines are written in EBCDIC, and they generally
produce EBCDIC output. This is not common, and it's probably becoming
less common with the passage of years, but there's nothing abnormal
about it.
But it must happen that programmers who work with such machines regularly
take functions stored as ASCII text, for example in the comp.lang.c FAQ, and
expect them to work on their platform.
Anyway, what is the PC I am typing this at? Would you call it a Unicode
machine or an ASCII machine? Surely it is really an attribute of the program
that happens to be running at the time, in a modern system.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
Malcolm said:
"Keith Thompson" <ks***@mib.orgw rote
>"Malcolm" <re*******@btin ternet.comwrite s:
It depends on what you mean by "normally".
There are still machines that use the EBCDIC character set. C programs on such machines are written in EBCDIC, and they generally produce EBCDIC output. This is not common, and it's probably becoming less common with the passage of years, but there's nothing abnormal about it.
But it must happen that programmers who work with such machines regularly
take functions stored as ASCII text, for example in the comp.lang.c FAQ,
and expect them to work on their platform.
Yes. When they move those programs to their platform, it typically undergoes
a translation process (e.g. ASCII to EBCDIC). It's commonplace, and easy to
do, although the various flavours of EBCDIC make it slightly more
interesting if you have to write the conversion yourself. Normally, though,
a mainframe is accessed via terminal emulation software which knows how to
do the translation for you, in either direction.
Anyway, what is the PC I am typing this at? Would you call it a Unicode
machine or an ASCII machine? Surely it is really an attribute of the
program that happens to be running at the time, in a modern system.
Right. Who cares? As long as there's a way to convert text to the relevant
character set, that's all that matters.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Rubin |
last post by:
How about adding a string interpolation method and a some print
methods to strings.
'hello world'.print() => same as "print 'hello world'". With optional
fd arg, print to file object
'hello world'.write() => same as "sys.stdout.write('hello world')"
i.e. print with no trailing newline
'hello $name'.interp() => like "'hello %s'%name"
'hello $name'.fprint() => like ('hello %s'%name).print()
'hello $name'.fwrite() => like ('hello...
|
by: Kit |
last post by:
Hey there, and thanks for reading a newbie post. I have a lex
assignment in which we are supposed to grab strings from a C source
file, and print them out to the screen, with escaped characters
"converted". Here's part of the assignment text:
----------------------------------------------------------------
Example:
main() {
char *s = "This is string one";
|
by: Prashanth Badabagni |
last post by:
Hi,
Can any body tell me how to print "hello,world" with out using semicolon
Thanks in advance ..
Bye
Prashanth Badabagni
|
by: kobu.selva |
last post by:
I was recently part of a little debate on the issue of whether
constants and string literals are considered "data objects" in C. I'm
more confused now than before.
I was always under the understanding that only "named" storage
areas(from the standard) were data objects. Since constants and string
literals don't have lvalues, they can't be data objects. Yet, I was
shown the first page of chapter 2 in K&R2, which states that variables...
|
by: teachtiro |
last post by:
Hi,
'C' says \ is the escape character to be used when characters are
to be interpreted in an uncommon sense, e.g. \t usage in printf(),
but for printing % through printf(), i have read that %% should be used.
Wouldn't it have been better (from design perspective) if the same
escape character had been used in this case too.
Forgive me for posting without verfying things with any standard
compiler, i don't have the means for now.
| |
by: Patrick De Ridder |
last post by:
How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.
Many thanks,
Patrick.
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
|
by: Duncan Winn |
last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that
requires an LPTSTR.
I have defined this as a:
char * data_name;
I am then trying to convert this to an LPOLESTR and I have done this as
follows:
LPOLESTR dunk_data = (LPOLESTR)T2CW(data_name);
|
by: DazedAndConfused |
last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the
left and right where there is no print.
The document displays perfect in print preview, but when I print it, about
1/2 inch on the right is not printed (leaving about 3/4 inch empty margin on
the right side of the page). The left side starts about 1/4 inch in and
prints just like I expect it to.
I tried setting the margins to 0 and OriginAtMargins = True. The print...
|
by: hamil |
last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview
control, the PageSetup control, and the Print dialog control. The code
attached is a concatination of two examples taken out of a Microsoft book,
"Visual Basic,Net Step by Step" in Chapter 18.
All but the bottom two subroutines will open a text file, and then allow me
to use the above controls, example 1. The bottom two subroutines will print
a graphic file, example...
|
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...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |