Warning I've never seen before

Posted by Greven on Wed 15 Oct 2003 05:36 PM — 7 posts, 23,286 views.

Canada #0
In a project I'm working on, I seem to have come across an warning I don't think I've seen before:
warning: passing arg 1 of `smash_space' discards qualifiers from pointer target type
The culprit is this line:
	    fprintf( fp, "%s.race\n", smash_space(race_table[count].race_name) );
My smash_space function is this:
char *smash_space( char *str ) 
{ 
static char ret[MAX_STRING_LENGTH]; 
char *retptr; 
retptr = ret; 
for ( ; *str != '\0'; str++ ) 
{ 
if (*str == ' ' ) 
continue;
else 
{ 
*retptr = *str; 
retptr++; 
} 
} 
*retptr = '\0'; 
return ret; 
} 
Clearly, my compiler is complaining about the type of information being passed into the function. Any ideas on how I can resolve this warning? It works properly, but I hate having warnings in my code.
USA #1
What's the type for race_name in the race_table struct?
Canada #2
char 	race_name	[16];
Amended on Wed 15 Oct 2003 08:46 PM by Greven
Canada #3
Well, apparently the problem is that my race_table is a const structure. Still, I dunno what I would do to fix it. Any ideas?
USA #4
Change:
char *smash_space( char *str )
to:
char *smash_space( const char *str )

This is generally good practice anyways. If your function isn't going to modify the pointer passed as an argument, the pointer should be passed as const.
Canada #5
cleared it right up, thanks.
Canada #6
Thats what i said! SEEESH