1.求一组字符串中最长的数字子串的长度。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int countMax(char * input,char * output) {
int len = 0;
int max = 0;
char * tem = NULL;
char * target = NULL;
while(*input++!='0') {
if(*input>='0'&& *input<='9') {
if(tem==NULL) {
tem = input;
}
len++;
} else {
if(len>max) {
max = len;
len = 0;
}
tem = NULL;
len = 0;
}
}
output[max] = '\0';
return max;
}
int main(void) {
char * str= "zhang131313321sdfdsfdd85458";
char point[1024] = " ";
int maxNum = countMax(str,point);
printf("%d\n",maxNum);
int length = sizeof(point)/sizeof(point[0]);//求得数组长度
system("pause");
return 0;
}
2.比较两个字符串的大小。
int myStrCom(char * str1,char * str2) {
char *p,*q;
p = str1;
q = str2;
while(*p&&*q&&*p==*q) {
p++;
q++;
}
return *p-*q;
}