This:
if(a[i]==' '&& a[i+1]!=' ');
strcpy(a,a[i+1]);
does not make sense. First the semicolon after the if statement makes it a no-op. And the strcpy
is also incorrect.
I guess you want to strip out a single character and thus wanted to write strcpy(a, &a[i+1])
. That second parameter needs to be a pointer (a[i+1]
is a char
) That is however invalid as the source and destination overlap.
for possibly overlapping memory you need to use memmove
, but there you have to specify the number of bytes to move (and not forget the terminating zero): memmove(a, &a[i+1], strlen(a)-i)
(the number of chars to copy is strlen(a)-(i+1)
and we need to add one for the terminating zero)
So that code becomes:
if(a[i]==' '&& a[i+1]!=' ') {
memmove(a, &a[i+1], strlen(a)-i);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…