Soft Ware/C 언어!!

입력받는 문자열에서 숫자만 추출하기

달려가보자 2011. 12. 1. 22:06


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <Windows.h>

__int64 first;
__int64 end;

unsigned int c_Conversion_number(char *HeadPoint,char *NodePoint,int size);
int cString_extraction(char * Data, unsigned int ** pString);

int main()
{
 char cString[1000];
 int nData=0;
 unsigned int *nPointdata=0;

 printf("string input : ");
 gets(cString);
 first = __rdtsc();
 nData = cString_extraction(cString,&nPointdata);
 end = __rdtsc();
 if(nData==0)
  {
   printf("No Data\n");
   return 0;
  }
 while(*nPointdata != 0)
 {
  printf("정수 값 출력 : %d\n",(*nPointdata));
  nPointdata++;
 }
 printf("Time:%d\n",end-first);

}

unsigned int c_Conversion_number(char *HeadPoint,char *NodePoint,int size)
{
 unsigned int Data=0,realData=0;
 for(;HeadPoint<NodePoint;HeadPoint++)
 {
  Data=(unsigned int)pow((long double)10,size--);
  Data=Data*(*HeadPoint-'0');
  realData+=Data;
 }
 return realData;
}
int cString_extraction(char * Data, unsigned int ** pString)
{

 int m_size = 0,choise = 0,cs_Byte=0,nCount=0,nData=0,goto_Data=0;
 char *HeadPoint = 0;
 unsigned int *NodePoint=0;

 m_size = sizeof(m_size);

 for(;*Data != NULL;Data++)
 { 
  if((*Data-'0')>=0 && (*Data-'0')<=9 && choise == 0)
  {
    choise = 1;
    nCount++;
    HeadPoint = Data;
  }
  
 
  else if(((*Data-'0')<0 || (*Data-'0')>9)&& choise == 1)
  {
real_Back:
    choise = 0;
    cs_Byte = Data - HeadPoint;
    *pString=(unsigned int *)realloc(*pString,(m_size*nCount));
    NodePoint=*pString;
    NodePoint=(NodePoint+(nCount-1));
    *NodePoint=c_Conversion_number(HeadPoint,Data,cs_Byte-1);
    if(goto_Data==1) break;
  }
 }
 
 if(choise == 1)
  {
   goto_Data=1;
   goto real_Back;
  }
 *pString=(unsigned int *)realloc(*pString,(m_size*nCount+1));
 NodePoint=*pString;
 NodePoint=NodePoint+nCount;
 *NodePoint=0;
 if(nCount==0) return 0;
 return nCount;
}