473,786 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there any way in C to print ® ?

Hi,

I'm looking for a way to print ® in a C program. Could any of you
help me out?

Regards,
Raju

Nov 15 '05 #1
21 4770
g.kanaka.r...@g mail.com wrote:
Hi,

I'm looking for a way to print ® in a C program. Could any of you
help me out?


putchar('®');

Though this is not strictly conforming since ® is not a member of the
basic
execution character set.

Under C99, you can try...

putchar('\u00AE ');

You could do...

printf("®");

....and pipe your output through a html browser.

Lastly, just do printf("(R)");

--
Peter

Nov 15 '05 #2
try this:
/*CODE BEGINS*/
putchar(174);
/*CODE ENDS*/

it will only work however if your system character set supports that
character.

Nov 15 '05 #3
On 2005-11-15, Peter Nilsson <ai***@acay.com .au> wrote:
g.kanaka.r...@g mail.com wrote:
Hi,

I'm looking for a way to print ® in a C program. Could any of you
help me out?


putchar('®');

Though this is not strictly conforming since ® is not a member of the
basic
execution character set.

Under C99, you can try...

putchar('\u00AE ');

You could do...

printf("®");

...and pipe your output through a html browser.

Lastly, just do printf("(R)");


What's the legal status of (R)? I know that (c) doesn't have any legal
status, though it hardly matters in jurisdictions where copyright is
automatic.
Nov 15 '05 #4

Peter Nilsson wrote:

Though this is not strictly conforming since ® is not a member of the
basic
execution character set.

Under C99, you can try...

putchar('\u00AE ');

You could do...

printf("®");

Being more generic, you can lookup the character/symbol that you want
to print in a ascii table. 174 is ascii for (R).

http://www.arachnoid.com/javascript/ascii.html

Nov 15 '05 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sandeep wrote:
[snip]
174 is ascii for (R).
Wrong. ASCII only extends from codepoint 0 through to codepoint 127. Any
characterset that has other codepoints /is not ASCII/.
http://www.arachnoid.com/javascript/ascii.html


A more definitive source would be the ISO, ANSI or ECMA standards
documents. Of the three, the ECMA documents are the only 'free' ones
around. Check
http://www.ecma-international.org/pu...T/Ecma-006.pdf
and
http://www.ecma-international.org/pu...t/ECMA-048.pdf

Alternatively, you can take a look at the ISO/IEC JTC 1/SC 2 definition
of ASCII at http://anubis.dkuug.dk/i18n/charmaps/ASCII
- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDehn+agV FX4UWr64RAh+BAK Ctk1PS+BGLQkUtv 3+eR3HUx813tgCf babQ
kuixvCOLPPDn44I Zl0+Hkak=
=pknL
-----END PGP SIGNATURE-----
Nov 15 '05 #6
Sandeep wrote:
Peter Nilsson wrote:

Though this is not strictly conforming since ® is not a member of the
basic
execution character set.

Under C99, you can try...

putchar('\u00AE ');

You could do...

printf("®");

Being more generic, you can lookup the character/symbol that you want
to print in a ascii table. 174 is ascii for (R).


Last I checked ASCII used seven bits to represent character values and
there are not 174 different possible encodings with 7 bits. Certain
extended codesets may define larger values using more bits but they are
not ASCII.

Robert Gamble

Nov 15 '05 #7
On 2005-11-15 12:10:43 -0500, "Sandeep" <sa************ @gmail.com> said:

Being more generic, you can lookup the character/symbol that you want
to print in a ascii table. 174 is ascii for (R).

http://www.arachnoid.com/javascript/ascii.html


This is not true, but is a common misconception. ASCII has values in
the range [0, 127]. Any character value that is greater than 127 is
*not* ASCII.
--
Clark S. Cox, III
cl*******@gmail .com

Nov 15 '05 #8
g.***********@g mail.com wrote:
Hi,

I'm looking for a way to print ® in a C program. Could any of you
help me out?


Yeah, this should work...

#include <wchar.h>
#include <locale.h>

int main(void)
{
setlocale(LC_CT YPE, "");
putwchar(L'\u00 AE');
putwchar(L'\n') ;
return 0;
}

Here is what happens when I run it on my system:

[sbiber@eagle c]$ echo $LANG
en_AU.UTF-8

This means that my system locale is set to Australian English, and the
execution character set is UTF-8.

[sbiber@eagle c]$ c99 -pedantic regtr.c -o regtr

It compiles cleanly as a C99 program.

[sbiber@eagle c]$ ./regtr
®

When run in the usual way, it outputs a registered trademark symbol in
the locale's character set, UTF-8.

[sbiber@eagle c]$ LANG=C ./regtr
(R)

When run in the C locale, it outputs the best-possible ASCII
representation of the character, which is the three characters '(', 'R',
')'.

[sbiber@eagle c]$ LANG=en_AU.ISO-8859-1 ./regtr | iconv -f ISO-8859-1
®

When run in the locale corresponding to Australian English in the
ISO-8859-1 character set, it outputs the registered trademark symbol in
that character set, which I then send to the 'iconv' command to convert
it from that character set back into the system default, UTF-8.

--
Simon.
Nov 16 '05 #9
Peter Nilsson wrote:
g.kanaka.r...@g mail.com wrote:
Hi,

I'm looking for a way to print ® in a C program. Could any of you
help me out?

putchar('®');

Though this is not strictly conforming since ® is not a member of the
basic
execution character set.


This does NOT work even on some systems where '®' is a member of the
execution character set, because the character '®' may be a multi-byte
character. To be specific, on this Linux machine it consists of the two
bytes 0xC2 and 0xAE:

[sbiber@eagle c]$ echo -n ® | od -t x1
0000000 c2 ae
0000002
Under C99, you can try...

putchar('\u00AE ');


This has the same problem, as \u00AE may be a multi-byte character. One
correct solution is to put it in a string.

For example, puts("®") will always work so long as the character exists
in the source and execution character sets, even if it happens to take
more than one byte.

If you can't guarantee that the source character set contains the
character, you can use a universal character sequence, ie.
puts("\u00AE"). This will still fail if the execution character set does
not contain that character, of course.

#include <stdio.h>
#include <locale.h>

int main(void)
{
setlocale(LC_CT YPE, "");
puts("This is using a literal character: ®");
puts("This is using a universal character sequence: \u00AE");
return 0;
}

[sbiber@eagle c]$ c99 -pedantic regtr.c -o regtr
[sbiber@eagle c]$ ./regtr
This is using a literal character: ®
This is using a universal character sequence: ®

--
Simon.
Nov 16 '05 #10

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

Similar topics

12
2407
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__ {}
14
2919
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version: $Revision: 0.0 $
0
1833
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html There is also a wiki page that collects the ideas: http://wiki.python.org/moin/PrintAsFunction There is the will to keep the printing operation very simple for the most common situation, but at the same time to make it flexible (optional no...
1
5721
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...
1
2324
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php but now I am not sure if that makes sense. Can you tell me please ? <html> <head>
3
2109
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for improvement. And of course it's possible there's some serious "gotcha" I've overlooked. Thus I welcome any and all comments. If there's some agreement that this proposal is worth further consideration then I'll re-submit a formal document in...
69
3225
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of this pep would be to make it impossible to use the name 'print' in a backward compatible manner. Indeed, if a program is to compile in both Python 2.x and Python 3.x, the print function (or the print statement with parentheses) can not use the...
2
22123
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I select the print directly option, it also prints right away to the defauilt printer. However, if I use the printer dialog control to print and I click 'OK' to actually print the document - nothing happens. The job does not even go into the print...
7
10763
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems like it would be helpful with transitioning.
12
3541
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to print the report three times, but do not know how
0
9647
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
9496
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
10363
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, 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...
1
10110
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,...
0
9961
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
8989
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...
0
6745
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();...
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.