2011-01-05 2 views

답변

5

here에 설명 된 REST API가 있습니다. 당신은 내가 자신의 자원을 사용하고 파이프를 만든 pwc에 C.에서

1

감사가 충분히 쉽게 접근 할 수 있어야하고, 여기

char chrptr_GoogleResponse [0x1000]; 
    char* chrptr_pos2 = NULL; 
    char* translate_text = search_str;   
    char* lang_pairs = "&langpair=es%7Cen'";  // language pairs 
    bool boNoError = true; 

    strcpy(chrarray_GoogleCommand, "curl -s -e http://www.my-ajax-site.com \ 
      'https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="); 

    strcat(chrarray_GoogleCommand, translate_text); 
    strcat(chrarray_GoogleCommand, lang_pairs); 

    popen(chrarray_GoogleCommand, "r"); 

    FILE* fileptrFile = popen(chrarray_GoogleCommand, "r"); 

if (fileptrFile == NULL) 
    { 
     printf("Error on opening pipe\n."); 
     exit(EXIT_FAILURE); 
    } 

while (!feof (fileptrFile)) 
    { 
     fgets (chrptr_GoogleResponse , 0x1000 , fileptrFile) ; 

     chrptr_pos1 = strstr(chrptr_GoogleResponse, "{\"translatedText\":\"") ; 
     if (chrptr_pos1) 
     { 
      chrptr_pos1 = chrptr_pos1 + strlen("{\"translatedText\":\"") ; 
      chrptr_pos2 = strstr(chrptr_GoogleResponse, "\"}, \"responseDetails\": null, \"responseStatus\": 200}") ; 
      if (chrptr_pos2) 
      { 
       memcpy(chrptr_temp, chrptr_pos1, chrptr_pos2 - chrptr_pos1); 
       memset((void*) ((unsigned long) chrptr_temp + (unsigned long) chrptr_pos2 - (unsigned long) chrptr_pos1), 0, 1); 
      } 
      else 
       boNoError = false ; 
     } 
     else 
      boNoError = false ; 

     if (feof (fileptrFile)) 
      break; 
    } 
    pclose(fileptrFile); 

    if (boNoError) 
     strcpy(search_str, chrptr_temp); //copy translated text. 
의 소스 코드입니다한다