You are not logged in.

#1 2012-02-19 23:32:25

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

[SOLVED!] Any way to escape a hash sign in a C header file?

Hello!

I am using snapwm, which is partly configured using a config.h. I would like to define a command in this config which takes 2 hex colour codes (e.g., #483839) as arguments so that I can later assign a keybinding to it. But I get error messages or warnings while compiling, it seems because of the '#' in the colour codes. Is there a way to 'escape' these hash signs to avoid the warnings and/or errors?

Here is the line in question:

const char* gradrnd         = {"gradrnd","'#000000'","'#444400'",NULL};

Last edited by hellomynameisphil (2012-02-21 00:21:00)

Offline

#2 2012-02-19 23:44:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED!] Any way to escape a hash sign in a C header file?

It's not from the hash sign.  It's because you're defining that as a char *, but you are intializing it as something else.

Try

const char* gradrnd[]         = {"gradrnd","'#000000'","'#444400'",NULL};

2nd Edit: portix beat me to it.

Last edited by Trilby (2012-02-19 23:47:31)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-02-19 23:45:37

portix
Member
Registered: 2009-01-13
Posts: 757

Re: [SOLVED!] Any way to escape a hash sign in a C header file?

You don't have to escape it, your declaration is wrong, you can change it to 

const char *gradrnd[] = {"gradrnd","'#000000'","'#444400'",NULL};

Offline

#4 2012-02-20 16:23:17

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

Re: [SOLVED!] Any way to escape a hash sign in a C header file?

Thanks portix. Still getting warning msgs. Here is the whole file:

http://paste.lisp.org/display/127876

When I run 'make', I get:

gcc -Wall   -c -o snapwm.o snapwm.c
In file included from snapwm.c:144:0:
config.h:65:1: warning: excess elements in scalar initializer
config.h:65:1: warning: (near initialization for 'gradrnd')
config.h:65:1: warning: excess elements in scalar initializer
config.h:65:1: warning: (near initialization for 'gradrnd')
config.h:65:1: warning: excess elements in scalar initializer
config.h:65:1: warning: (near initialization for 'gradrnd')
gcc  -s -Os -o snapwm snapwm.o -lX11

I don't get these warnings with the gradrnd line commented out.

Offline

#5 2012-02-20 17:24:34

prasinoulhs
Member
From: Greece
Registered: 2011-10-30
Posts: 53

Re: [SOLVED!] Any way to escape a hash sign in a C header file?

The file you linked misses a set of braces.

const char *gradrnd[] = {"gradrnd","'#000000'","'#444400'",NULL};

Offline

#6 2012-02-21 00:19:49

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

Re: [SOLVED!] Any way to escape a hash sign in a C header file?

Arrgh! So simple, and I should have noticed that myself, but I guess sometimes an outside eye is the best corrective. Problem solved. Thanks to all who helped.

Offline

Board footer

Powered by FluxBB