指针逆转字符串:
int inverse(char *buf)
{
if (buf == NULL)
{
printf("buf==NULL");
return -1;
}
int length = strlen(buf);
char *p1 = buf;
char *p2 = buf + length - 1;
while (p1 < p2)
{
char c = *p1;
*p1 = *p2;
*p2 = c;
p1++;
p2--;
}
return 0;
}
int inverse02(char *p)
{
if (p == NULL)
{
return -1;
}
if (*p == '\0')
{
return 0;
}
inverse02(p + 1);
printf("%c", *p);
}
int inverse03(char *p)
{
if (p == NULL)
{
return;
}
if (*p == '\0')
{
return;
}
inverse03(p + 1);
//printf("%c", *p);
strncat(g_buf, p, 1);
}
int inverse04(char *p,char *mybuf)
{
if (p == NULL||mybuf==NULL)
{
return;
}
if (*p == '\0')
{
return;
}
inverse04(p + 1,mybuf);
//printf("%c", *p);
strncat(mybuf, p, 1);
}
俩头绪模型
int getCount(char *p, int *count)
{
if (p == NULL || count == NULL)
{
printf("p == NULL || count == NULL");
return -1;
}
int i = 0;
int j = strlen(p) - 1;
while (isspace(p[i]) && p[i] != '\0')
{
i++;
}
while (isspace(p[j]) && p[j] != '\0')
{
j--;
}
int AllCount = j - i + 1;
*count = AllCount;
return 0;
}
int trimSpace(char *p, char *newstr)
{
if (p == NULL || newstr == NULL)
{
printf("p == NULL || count == NULL");
return -1;
}
int i = 0;
int j = strlen(p) - 1;
while (isspace(p[i]) && p[i] != '\0')
{
i++;
}
while (isspace(p[j]) && p[j] != '\0')
{
j--;
}
int AllCount = j - i + 1;
p = p + i;
strncpy(newstr, p, AllCount);
newstr[AllCount] = '\0';
return 0;
}
int trimSpace1(char *p)
{
if (p == NULL)
{
printf("p == NULL || count == NULL");
return -1;
}
int i = 0;
int j = strlen(p) - 1;
while (isspace(p[i]) && p[i] != '\0')
{
i++;
}
while (isspace(p[j]) && p[j] != '\0')
{
j--;
}
int AllCount = j - i + 1;
//p = p + i;
strncpy(p, p+i, AllCount);
p[AllCount] = '\0';
return 0;
}