int main()
{
	int x;
	int arrayList[9];
	int i;
	int arrayCount = 0;	

	scanf("%d", &x);

	for(i = 0; i < 10; i++)
	{
		arrayList[i] = 0;
	}

	while(arrayCount <= 10)
	{
		i++;
		
		if(i % 10 == x)
		{
			int check = numberCheck(i);
			if(check != 0)
			{
				arrayList[arrayCount] = i;
				arrayCount++;
			}			
		}
	}
	

	for(i = 0; i < 10; i++)
	{
		if(arrayList[i] == 0)
		{
			printf("NOT possible ");
		}
		else
		{
			printf("%d ",arrayList[i]);
		}	
	}

	return 0;
}
Ejemplo n.º 2
0
// read state file and give structure back or NULL
struct strDivideState * fileStateLoad( char *filename )
{
   // open file voor reading
   FILE *strFile        ;
   char  cLine[   4096 ];
   char  cDummy1[ 4096 ];
   char  cDummy2[ 4096 ];
   int   iDummy         ;
   int   iLen           ;
   char *linechar       ;
   int   iLineNr        ; // current line numer
   int   iEnd           ; // is end tag found 1=yes
   int   iState         ; // state of current 
   int   iWalkBlok      ; // current walk blok
   int   iOverflowblok  ; 
   int   iCnt           ;
   
   struct strDivideState *strState = NULL ; // the state too be returned
   struct strWalkState   *oWalk    = NULL ; // current walk blok
   
   
   strFile = fopen( filename, "r");
   if ( strFile == NULL ) {
      return NULL ;
   }
   
   iLineNr = 0 ;
   iEnd    = 0 ;
   iState  = 0 ; // 0 noting, 1=start found
   while ( fgets( cLine, sizeof(cLine), strFile )) {
      iLineNr++;
      iLen = strlen( cLine );
      
      // remove next lines
      for( linechar = cLine + iLen - 1 ; linechar > cLine;  linechar-- ) {
         if ( *linechar == '\r' || *linechar == '\n' ) {
            *linechar = '\0';
         } else {
            break;
         }
      }

      iLen = strlen( cLine );
      // min length with data is 2 char, used too skip empty lines
      if ( iLen <  2 ) {
         continue ;
      }
      // # = comment string
      if ( cLine[ 0 ] == '#' ) {
         continue;
      }
      
//      printf( "Line: %d; %s\n", iLineNr, cLine );
      
      // end of state file reach
      if ( strcmp( cLine, "[End]" ) == 0 ) {
         iEnd = 1 ;
         break;
      }
      
      // start of blok
      if ( strcmp( cLine, "[NumberState]" ) == 0 ) {
         if ( iState != 0 ) {
            fprintf( stderr, "Incorrecte [NumberState] at line %d, file %s\n", iLineNr, filename );
            break;
         }
         iState = 1 ;
         continue ;
      }
      
      
      if ( iState  == 1 ) {
         // state = 1 main block
         // state = 2 walk blok
         if ( strncmp( cLine, "number", 6 ) == 0 ) {
            sscanf( cLine, "%s : %s", cDummy1, cDummy2 );
            
            if ( strlen( cDummy2 ) < 1 ) {
               fprintf( stderr, "No valid number '%s' at linenr %d, file %s\n", cDummy2, iLineNr, filename );
               break;
            }
            if ( numberCheck( cDummy2 ) != 0 ) {
               fprintf( stderr, "No valid number '%s' at linenr %d, file %s\n", cDummy2, iLineNr, filename );
               break;
            }
            // create state 
            strState = strDivideStateAlloc( cDummy2 ) ;
            
            // printf( "Number found: %s\n", cDummy2 );
         } else {
            if ( strState == NULL ) {
               fprintf( stderr, "Number must be the first parameter '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
               break;
            }                          //12345678901
            if        ( strncmp( cLine, "iLenNumber" , 10 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iLenNumber  ); 
            } else if ( strncmp( cLine, "iMaxCurNr"  ,  9 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iMaxCurNr   ); 
            } else if ( strncmp( cLine, "iMinCurNr"  ,  9 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iMinCurNr   ); 
            } else if ( strncmp( cLine, "iMaxLenNum1", 11 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iMaxLenNum1 ); 
            } else if ( strncmp( cLine, "iMaxLenNum2", 11 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iMaxLenNum2 ); 
            } else if ( strncmp( cLine, "iLenHalve"  ,  9 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iLenHalve   ); 
            } else if ( strncmp( cLine, "iCurNumber" , 10 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iCurNumber  ); 
            } else if ( strncmp( cLine, "iFound"     ,  6 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &strState->iFound      ); 

            } else if ( strncmp( cLine, "[Current_"  ,  9 ) == 0 ) { 
               sscanf( cLine, "%9s%d"  , cDummy1, &iWalkBlok );
               // must always be 0 = first blok
               if( iWalkBlok != 0 ) {
                  fprintf( stderr, "Incorrect blok '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
                  break;
               }
               iState = 2 ; // read blok
               oWalk  = strState->arrWalk + iWalkBlok ; // current walk blok
            } else {
              fprintf( stderr, "Unknown field '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
              break ;
            }
         }
      } else if ( iState == 2 ) { //12345678901234
         if ( strncmp( cLine, "[Current_"  ,  9 ) == 0 ) { 
           sscanf( cLine, "%9s%d"  , cDummy1, &iWalkBlok );
           // check 1, 0 is bij de blobk above
           if( iWalkBlok < 1 || iWalkBlok > strState->iMaxCurNr ) {
              fprintf( stderr, "Blok nr: %d, %s\n", iWalkBlok, cDummy1 );
              fprintf( stderr, "Incorrect blok '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
              break;
           }
           oWalk  = strState->arrWalk + iWalkBlok ; // current walk blok         
         } else if ( strncmp( cLine, "iDigit"         ,  6 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iDigit         ); 
         } else if ( strncmp( cLine, "iOverflowValue" , 14 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iOverflowValue );   
         } else if ( strncmp( cLine, "iOverflowStart" , 14 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iOverflowStart );   
         } else if ( strncmp( cLine, "iOverflowPos"   , 12 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iOverflowPos   );   

         } else if ( strncmp( cLine, "iLastWalk"      ,  9 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iLastWalk      );   
            
         } else if ( strncmp( cLine, "iWalk1"         ,  6 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iWalk1         );   
         } else if ( strncmp( cLine, "iWalk2"         ,  6 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iWalk2         );   
         } else if ( strncmp( cLine, "iStart1"        ,  7 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iStart1        );   
         } else if ( strncmp( cLine, "iStart2"        ,  7 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->iStart2        );   
         } else if ( strncmp( cLine, "bCalc1"         ,  6 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->bCalc1         );   
         } else if ( strncmp( cLine, "bCalc2"         ,  6 ) == 0 ) { sscanf( cLine, "%s : %" SCNdFAST8 , cDummy1, &oWalk->bCalc2         );   
         } else if ( strncmp( cLine, "Overflow_"      ,  9 ) == 0 ) { 
            sscanf( cLine, "%9s%d : %d", cDummy1, &iOverflowblok, &iDummy );
            if ( iOverflowblok < 0 || iOverflowblok > 3 * strState->iLenNumber ) {
               fprintf( stderr, "Incorrect overflow '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
               break;
            } 
            oWalk->OverflowDigits[ iOverflowblok ] = iDummy ;
         } else if ( strncmp( cLine, "number1"      ,  7 ) == 0 ) {
            sscanf( cLine, "%s : %d", cDummy1, &iDummy );
            strState->iNumbers1[ iWalkBlok ] = iDummy ;
         } else if ( strncmp( cLine, "number2"      ,  7 ) == 0 ) { 
            sscanf( cLine, "%s : %d", cDummy1, &iDummy );
            strState->iNumbers2[ iWalkBlok ] = iDummy ;
         } else {
            fprintf( stderr, "Unknown field '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
            break ;
         }
      } else {
         fprintf( stderr, "Unknown line '%s' at linenr %d, file %s\n", cLine, iLineNr, filename );
         break;
      }
   }
   
   if ( iEnd != 1 ) {
      strDivideStateFree( strState );
      strState = NULL ; 
   } else {
      // restore last
      for ( iCnt = 1; iCnt <= strState->iCurNumber; iCnt++ ) {
         oWalk = strState->arrWalk + iCnt ;
         oWalk->strLast = &(glb_arrNoLastMulAdd[ oWalk->iDigit ][ oWalk->iOverflowValue ][ strState->iNumbers2[ 0 ] ][ strState->iNumbers1[ 0 ] ] );
      }
      
      // consistency check strState ????
   }
   
   fclose( strFile );
   
   return strState ;
}