I wrote a function that cuts a string (sentence of words) by the required length. I do not want the phrase abbreviation to be in the middle of a single word. So I skip n characters until I get to the place and cut the sentence line. My problem is not really a problem, compiling my function spits out a warning saying that "warning: the calculated value is not used", see the Commented line in the code. The function works as expected. Therefore, either I am blind, or I sit for a long time in my project, in fact I do not understand this warning. Can someone point me to a lack of 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)"
source share