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

Syntax error on #define

Hi,

I tried compiling this code -

int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");
}

with gcc version 2.96. I get this error message -

parse error before `abc'

Please explain, whats wrong here. The intention is to print a string
in bold characters on the screen.

Thanks,
Anshul

Mar 8 '07 #1
8 2142
Oops, bad subject line.

Thanks,
Anshul
Mar 8 '07 #2
Anshul wrote:
Hi,

I tried compiling this code -

int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");
Only adjacent string literals are concactenated. The expression abc is
not a string literal, but a pointer constant value.

Try:

printf("\033[1m", " %s ", "\033[m\n", "doing");

Mar 8 '07 #3
"Anshul" <an******@gmail.comschrieb im Newsbeitrag
news:11**********************@30g2000cwc.googlegro ups.com...
Hi,

I tried compiling this code -
#include <stdio.h>
int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");
printf("\033[1m%s\033[m" , "doing");
fflush(stdout);
return 0;
}

with gcc version 2.96. I get this error message -

parse error before `abc'

Please explain, whats wrong here. The intention is to print a string
in bold characters on the screen.

Thanks,
Anshul
Bye, Jojo
Mar 8 '07 #4

"santosh" <sa*********@gmail.comschrieb im Newsbeitrag
news:11*********************@s48g2000cws.googlegro ups.com...
Anshul wrote:
>Hi,

I tried compiling this code -

int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");

Only adjacent string literals are concactenated. The expression abc is
not a string literal, but a pointer constant value.

Try:

printf("\033[1m", " %s ", "\033[m\n", "doing");
Still doesn't work, got to be:
printf("\033[1m%s\033[m\n", "doing");

Bye, Jojo
Mar 8 '07 #5
santosh said:
Anshul wrote:
>Hi,

I tried compiling this code -

int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");

Only adjacent string literals are concactenated. The expression abc is
not a string literal, but a pointer constant value.

Try:

printf("\033[1m", " %s ", "\033[m\n", "doing");
Er, no. :-)

printf("\033[1m%s\033[m\n", "doing");

or even just:

printf("\033[1mdoing\033[m\n");

(although the former version is perhaps slightly more maintainable, in
that it's easier to see what needs changing when the need arises).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 8 '07 #6
In article <11*********************@s48g2000cws.googlegroups. com>,
santosh <sa*********@gmail.comwrote:
>Only adjacent string literals are concactenated. The expression abc is
not a string literal, but a pointer constant value.

Try:

printf("\033[1m", " %s ", "\033[m\n", "doing");
^ ^

Take out those commas!

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 8 '07 #7

santosh wrote:
Anshul wrote:
Hi,

I tried compiling this code -

int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");

Only adjacent string literals are concactenated. The expression abc is
not a string literal, but a pointer constant value.

Try:

printf("\033[1m", " %s ", "\033[m\n", "doing");
Sorry to all about this. It should be:

printf("\033[1m" "%s" "\033[m\n", "doing");

or better yet, versions that Richard, Richard and Joachim posted.

Mar 8 '07 #8
In article <j2***************@news.cpqcorp.net"Joachim Schmitz" <no************@hp.comwrites:
"santosh" <sa*********@gmail.comschrieb im Newsbeitrag
news:11*********************@s48g2000cws.googlegro ups.com...
Anshul wrote:
Hi,

I tried compiling this code -

int main()
{
char abc[10] = "%s";
printf("\033[1m" abc "\033[m" , "doing");
Only adjacent string literals are concactenated. The expression abc is
not a string literal, but a pointer constant value.

Try:

printf("\033[1m", " %s ", "\033[m\n", "doing");
Eh, no. But the following *will* work:
#define abc "%s"
printf("\033[1m" abc "\033[m", "doing");
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Mar 8 '07 #9

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

Similar topics

8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
6
by: Raghuveer Pallikonda | last post by:
Hi, I am trying to stub out debug log messages in my application, if the logging subsystem is not enabled.. For e.g a invocation #define LOGMSG !Logger::Enabled() ? false : Logger::LogMsg so...
2
by: kalpana.sinduria | last post by:
Hi all, how to remove the following complle error. When I compiling the code I get the following errors: Compiling... CDrtEachDefFeat.cpp d:\ include\common\cdrtintegfeat.h(39) : error...
4
by: Jeremy Yallop | last post by:
Looking over some code I came across a line like this if isalnum((unsigned char)c) { which was accepted by the compiler without complaint. Should the compiler have issued a diagnostic in this...
26
by: GS | last post by:
I am doing my first real embedded programming project and the supplied device libraries have a function definition that looks like this: void FCN(void) = { INTDEF, INTABS, (unsigned short)...
16
by: danu | last post by:
I have a structure : typedef struct{ char magicNum; int width; int height; int maxGrey; int pixels; } ImageT;
0
by: Travis Oliphant | last post by:
This post is to gather feedback from the wider community on PEP 357. It is nearing the acceptance stage and has previously been discussed on python-dev. This is a chance for the wider Python...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
3
by: thalinx | last post by:
Hi can anyone please help i have an error which says declaration syntax error at the main function thanks # include<stdlib.h> # include<conio.h> # include<stdio.h> # define MAXREN 3 #...
2
by: tvnaidu | last post by:
I am getting this error for line 108, I kept C code also below, any idea?. main.c:108: underscore in number main.c:108: syntax error before numeric constant 104: #define...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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
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.