查找最大的數字子串

// Interview100.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int maxSubStr(char* str){
    int len = 0;
	char *pstart = NULL;
	int max = 0;
	while(1){
	    if(*str >= '0' && *str <='9' ){
			len++;
		} else {
			if(len > max){
			    max = len;
				pstart = str - len;
			}

			len = 0;
		    
		}

		if(*str == '\0'){
			break;
		} else {
		   str++;
		}
	}

	return max;
}

int _tmain(int argc, _TCHAR* argv[])
{
	//printf("hello world\n");
	char* str = "hello world!";
	//maxSubStr(str);
	int max = maxSubStr("hello world!12");
	printf("%d", max);
	getchar();
	return 0;
}
相關文章
相關標籤/搜索