I wrote a function that that shortens a string (sentence of words) at requested length. I do not want that a the cut of the sentence happens to be in middle of a single word. So i skip back n chars until I reach a space and cut the sentence string there.
My problem is not really a problem, compiling my function spits out a warning that says “warning: value computed is not used”, see the commented line in the code. The function works as expected though.
So either I am blind, or I am sitting to long on my project, actually I do not understand that warning. Could anybody please point me the flaw in the function?
char *
str_cut(char *s, size_t len) {
char *p = NULL;
int n = 3;
p = s + len;
if (p < (s + strlen (s))) {
/*
* do not cut string in middle of a word.
* if cut-point is no space, reducue string until space reached ...
*/
if (*p != ' ')
while (*p != ' ')
*p--; // TODO: triggers warning: warning: value computed is not used
/* add space for dots and extra space, terminate string */
p += n + 1;
*p = '\0';
/* append dots */
while (n-- && (--p > s))
*p = '.';
}
return s;
}
My compiler on the development machine is “gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)”
The warning is due to the
*(dereference) — you aren’t using the dereferenced value anywhere. Just make it:and the warning should go away.