没事做了一个查找最小的子串的题目
源代码如下:
#include <stdio.h>
main()
{
char *a="fdsf fdsfasf fasfafasf fdafa fafaa asdf afdfsfsdfsfsdfsdfsd";
char *ptr;
int max=0,num=0;
ptr=a;
while(*ptr!='/0')
{
if((*ptr)!=32)
{
num++;
if(num>max)
{
max=num;
}
}
else
{
if(num>max)
{
max=num;
}
num=0;
}
ptr++;
}
printf("the max child string is %d/n",max);
}
总结一下,需要注意的几点如下:
第一.判断取到的子串等不等于空格的语句为 if((*ptr)!=32),而不是if((*ptr)!=''),如果那样的话编译器报错为</