Re: What does const char *s mean? is s a constant or *s?
From: Jonathan Burd (jonathan.burd_at_REMOVEMEgmail.com)
Date: 01/24/05
- Next message: Christian Bau: "Re: What makes a good C/C++ programmer?"
- Previous message: pete: "Re: What does const char *s mean? is s a constant or *s?"
- In reply to: G Patel: "What does const char *s mean? is s a constant or *s?"
- Next in thread: Karthik Kumar: "Re: What does const char *s mean? is s a constant or *s?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 24 Jan 2005 14:44:15 +0530
G Patel wrote:
> I've been looking at some code for string functions (certain
> implementation of them) and the non modified string is usually declared
> as a const char *s in the parameter list.
>
> I was wondering, what exactly does that mean. Does that mean the
> function is restricted from changing the address (changing s) or
> changing what's being pointed to (*s)?
>
See what the compiler tells you when you try to compile it:
(gcc -pedantic -Wall -std=c89 -o complain complain.c)
/* complain.c */
#include <stdio.h>
void
replace_spaces_with_hyphens (/* >> */ const char *, const char *);
void
replace_spaces_with_hyphens (/* >> */ const char *buf, const char *str)
{
int ch;
while ((ch = *str))
{
if (*str == ' ')
ch = '-';
*buf = ch;
++buf;
++str;
}
*buf = '\0';
}
int
main (int argc, char **argv)
{
char buf[100];
const char *str = "foo licious";
replace_spaces_with_hyphens (buf, str);
puts (buf);
return 0;
}
Regards,
Jonathan.
-- "Women should come with documentation." - Dave
- Next message: Christian Bau: "Re: What makes a good C/C++ programmer?"
- Previous message: pete: "Re: What does const char *s mean? is s a constant or *s?"
- In reply to: G Patel: "What does const char *s mean? is s a constant or *s?"
- Next in thread: Karthik Kumar: "Re: What does const char *s mean? is s a constant or *s?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|