473,396 Members | 2,018 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,396 software developers and data experts.

printf - Can't print "print\my\message"

ern
printf("C:\myfile.txt");

prints as

C:myfile.txt

How do I specify string literal ?

Jan 18 '06 #1
6 2203
ern
Got it... sorry for posting

Answer = printf("C:\\myfile.txt");

Just needed to include two \\

Jan 18 '06 #2

"ern" <er*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
printf("C:\myfile.txt");

prints as

C:myfile.txt
I doubt that. I suspect the compiler complained.
(because there's no '\m' character).

How do I specify string literal ?


As above, but note that certain 'unprintable'
characters have a special syntax for expressing
them, e.g. '\n' for newline, '\t' for tab, etc.
Since the '\' is used for this 'special purpose',
a special sequence is used to denote a literal
'\' character: '\\'.

printf("C:\\myfile.txt");

Look up 'escape character' in a C text.

-Mike
Jan 18 '06 #3

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:wJ*****************@newsread2.news.pas.earthl ink.net...

"ern" <er*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
printf("C:\myfile.txt");

prints as

C:myfile.txt


I doubt that. I suspect the compiler complained.
(because there's no '\m' character).


I doubt *any* of my compilers would complain about that...
which compiler do you use which *does* check for and
report issues with invalid escape sequences in format
strings?

Jan 18 '06 #4
"Mark B" <so***@localbar.com> wrote in message
news:43*********************@news.inteliport.com.. .

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:wJ*****************@newsread2.news.pas.earthl ink.net...

"ern" <er*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
printf("C:\myfile.txt");

prints as

C:myfile.txt


I doubt that. I suspect the compiler complained.
(because there's no '\m' character).


I doubt *any* of my compilers would complain about that...
which compiler do you use which *does* check for and
report issues with invalid escape sequences in format
strings?


Apologies to Mike... I checked after the fact for the hell of it
and was suprised to find that:
gcc version 3.4.2 does in fact complain ;-)
as does msvc cl 12.00.8168

They both however still create an executable which
provided output as specified by OP.

Mark
Jan 18 '06 #5
"Mark B" <so***@localbar.com> writes:
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:wJ*****************@newsread2.news.pas.earthl ink.net...

"ern" <er*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
printf("C:\myfile.txt");

prints as

C:myfile.txt


I doubt that. I suspect the compiler complained.
(because there's no '\m' character).


I doubt *any* of my compilers would complain about that...
which compiler do you use which *does* check for and
report issues with invalid escape sequences in format
strings?


Did you try it?

It's not an invalid format string, it's an invalid string literal.
puts("C:\myfile.txt") would have the same problem.

Strictly speaking, "C:\myfile.txt" isn't a string literal at all. The
compiler is required to issue a diagnostic, as it would for any syntax
error. At least one compiler then proceeds to generate code as if the
literal "C:yfile.txt" had appeared.

--
Keith Thompson (The_Other_Keith) 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.
Jan 18 '06 #6
On 2006-01-18 13:50:00 -0500, "Mark B" <so***@localbar.com> said:

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:wJ*****************@newsread2.news.pas.earthl ink.net...

"ern" <er*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
printf("C:\myfile.txt");

prints as

C:myfile.txt


I doubt that. I suspect the compiler complained.
(because there's no '\m' character).


I doubt *any* of my compilers would complain about that...
which compiler do you use which *does* check for and
report issues with invalid escape sequences in format
strings?

GCC does; and not just with format strings, but with any strings:

[littleclark2:~] clarkcox% cat test.c

int main()
{
"\a\s\d\f\g\h\j\k\l";
return 0;
}

[littleclark2:~] clarkcox% gcc test.c
test.c:4:3: warning: unknown escape sequence '\s'
test.c:4:3: warning: unknown escape sequence '\d'
test.c:4:3: warning: unknown escape sequence '\g'
test.c:4:3: warning: unknown escape sequence '\h'
test.c:4:3: warning: unknown escape sequence '\j'
test.c:4:3: warning: unknown escape sequence '\k'
test.c:4:3: warning: unknown escape sequence '\l'
[littleclark2:~] clarkcox%

--
Clark S. Cox, III
cl*******@gmail.com

Jan 18 '06 #7

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

Similar topics

1
by: Nick Li | last post by:
Hi, I am trying to print a value of a variable multiple times. For example, the value is "*" and I want to print it five times, like "*****". Can somebody show me a easy way to do it? Thanks...
29
by: JS | last post by:
I would like to print char 'd': main(){ char g; g = 'a'; g = 'b'; g = 'c'; g = 'd';
4
by: rom | last post by:
I need to print a html table when the user clicks on a key. the problem is that i don't want the printer dialog box to appear. i guess this is impossible in javascript so i think to create an...
0
by: dragonguy83 | last post by:
Hi guys, i have bee around these forums alot learning so much. hopefully someone will be able to help me out. here is my setup. i have a xp pro desktop connected to a netgear wireless router that...
4
by: ramaswamynanda | last post by:
Hello, I have an application in Access where I have developed about 10 reports. These have been working for a while and produce data properly. I recently tried exporting the report, from the...
10
by: laikon | last post by:
Hello, everyone: this is about overflow in C and C++. int c = 400; printf("%c", c); it print ? on screen, and ascii of '?' is 63.
3
by: Dan | last post by:
Hi, This may be the wrong place to ask this question, but here goes anyway. I have a RIA that I developed so that there is a scrollable div in the bottom right portion of the screen that always...
66
by: happyse27 | last post by:
Hi All, my html code is sno 1) and perl code is sno 2). a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it...
3
johny10151981
by: johny10151981 | last post by:
Around 3 years ago I got a problem. It was interesting for me, so I solved it. Compiler was turbo C/c++ 3.0. That is very old compiler. That program had very poor memory management as I can...
5
by: Ankit Khare | last post by:
As i read size of enum is sufficient enough to hold any integer value,thus its 4 bytes in my machine. typedef enum{ Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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...

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.