#include<stdio.h> int trimSpace(char *inbuf, char *outbuf) { int ret = 0; if (inbuf == NULL || outbuf == NULL) { ret = -1; return ret; } char * intail = inbuf; while (*intail!=‘\0‘) { intail++; } intail--; while (*intail==‘ ‘) { *intail = ‘\0‘; intail--; } while (*inbuf == ‘ ‘) { inbuf++; } while (*inbuf!=‘\0‘) { *outbuf++ = *inbuf++; } *outbuf = ‘\0‘; return ret; } int main() { char buf[] = " abhf dsiu qwe aaaaaaaaaa "; char out[50]; int ret; ret = trimSpace(buf, out); if (ret == 0) { printf("%s.", out); } else { printf("err:%d", ret); return ret; } return 0; }
时间: 2024-09-30 18:41:41