train.h
Code:
//PARSEPARA:parse para by step by step
int parseP(const char *a,float *p)
{
float start,end,step;
int pCount = 0;
int pNum = 0;
pNum = sscanf(a,"%f-%f-%f",&start,&end,&step);
//printf("start:[%f]\n",start);
if ( pNum < 3 )
{
printf("Error:format of windowSize,K-value,noequalPunish and percentRatio must be start-end-step.\n");
exit(0);
}
if ( end < start )
{
printf("Error: end must be more than start in [%s]\n",a);
exit(0);
} else if ( step <= 0 )
{
printf("Error: step must be more than 0 in [%s]\n",a);
exit(0);
}
//float j;
while ( start <= end )
{
*p = start;
start = start+step;
p++;
pCount++;
}
return pCount;
//printf("pNum:%f\n",step);
}
zero.cpp
Code:
#include "train.h"
int main( int argc,char *argv[])
{
float a[30] = {'\0'};
parseP("0-5-1",a);
for ( int i = 0; a[i] != '\0' ; i++ )
{
printf("a[%d]:%f\n",i,a[i]);
}
return 0;
}
If parseP("0-5-1",a); print is nothing
if parseP("1-5-1",a); print is as follows:
a[0]:1.000000
a[1]:2.000000
a[2]:3.000000
a[3]:4.000000
a[4]:5.000000
why ? how to solve this problem?