Codice: Seleziona tutto
" this is a test "
"this is a test"
Codice: Seleziona tutto
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void my_trim(char *s, unsigned int len)
{
char *b = s;
while ( len > 0 && isspace( (unsigned char) s [len - 1] ) )
len--;
while ( len > 0 && isspace(*b) )
{
b++;
len--;
}
memmove(s, b, len);
s[len] = '\0';
}
int main()
{
char s[]=" this is a test ";
unsigned int len;
len=strlen(s);
puts(s);
my_trim(&s,len);
printf("After trimming : %s\n",s);
return 0;
}
Codice: Seleziona tutto
trim.c: In function ‘main’:
trim.c:24:9: warning: passing argument 1 of ‘my_trim’ from incompatible pointer type [enabled by default]
my_trim(&s,len);
^
trim.c:5:10: note: expected ‘char *’ but argument is of type ‘char (*)[23]’
void my_trim(char *s, unsigned int len)
^
