Mail Archives: djgpp/2001/12/18/15:33:59
First off, this is not a C group so this post is off-topic here. You should
try comp.lang.c.moderated or comp.lang.c. I also suggest you take a look at
the FAQ list for that group (http://www.eskimo.com/~scs/C-faq/top.html).
Chris Amos <homie_dont_play_dat AT yahoo DOT com> wrote in
news:20011218200551 DOT 38218 DOT qmail AT web13907 DOT mail DOT yahoo DOT com:
> It has to be a logic error of some kind because the code runs fine
> aside from a few warning messages...
ahem ... please always compile your code with -Wall, and pay attention to
those warnings ... they mean something.
C:\var>cat s.c
void getstr(const char *string, const char *new_string, int
start_offset, int end_offset)
{
int i=0;
int b=0;
for (i=start_offset; i<=end_offset; i++) {
*(new_string+b)=string+i;
b++;
}
*(new_string+b)='\0';
return;
}
C:\var>gcc -Wall -c s.c
s.c: In function `getstr':
s.c:7: warning: assignment of read-only location
s.c:7: warning: assignment makes integer from pointer without a cast
s.c:10: warning: assignment of read-only location
you should think about what these warnings mean, and eliminate the reasons
for them.
now, obviously you don't really need this do you?
assuming
* new_string points to a large enough storage area
* start_offset is the index of the character you want to start copying from
* end_offset is the index of the character up to which will copy
there is nothing wrong with
strncpy(new_string, string + start_offset, end_offset - start_offset)
HTH.
Sinan.
--
--------------------------------
A. Sinan Unur
http://www.unur.com/
- Raw text -