for (p = s; *p; p++)//这一句不知道在干啥,那位解释一下。
dfczj 2007-05-09 10:48:24 例如:"R12"+1 == "R13" "R99"+1=="S00" "R19"+1=="R20"
加1后返回字符串 ~~~
--------------------------------------------
#include <stdio.h>
#include <string.h>
void string_inc(char *s)
{
char *p;
char c;
p = s;
for (p = s; *p; p++)//这一句不知道在干啥,那位解释一下。
;
c = 0;
p--;
(*p)++;
for (; p >= s; p--)
{
*p +=c;
switch (*p)
{
case '9' + 1:
*p = '0';
c = 1;
break;
case 'z' + 1:
c = 1;
*p = 'a';
break;
case 'Z' + 1:
c = 1;
*p = 'A';
break;
default:
c = 0;
}
}
}
int main(void)
{
char *ss[] = {"R12", "R99", "R19", "R12", "Rz9", "Ra9"};
char s[4];
int i, n;
n = sizeof(ss)/sizeof(ss[0]);
for (i = 0; i < n; i++)
{
strcpy(s, ss[i]);
printf("%s + 1 = ", s);
string_inc(s);
printf("%s\n", s);
}
return (0);
}