By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Syntax error on #define

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
Oops, bad subject line.

Thanks,
Anshul
Mar 8 '07 #2

P: n/a
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

P: n/a
"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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.