2013-02-13 3 views
0

로 읽습니다. 하지만 결과를 문자열 "bad"와 비교할 때 항상 "equal"이 아니라고합니다. 화면에 결과를 인쇄 할 때 두 결과가 모두 나쁜 것으로 표시됩니다.결과가 없습니다 내가 정말 작동하는지 "나쁜"내가 테스트 할 수 있습니다 할 수 있도록 웹 링크에서 반환 데이터를 설정 내가 POS 기계</p> <p>이 코드를 작성하고 문자열

제발 당신의 도움이 필요합니다.

void checklogin(void) { 
    CURL *curl; 
    CURLcode res; 
     long timeout = 30; 
     char buffer[50000]; 
    //Initializing the CURL module 
    curl = curl_easy_init(); 

    if(curl){ 
    //Tell libcurl the URL 
    curl_easy_setopt(curl,CURLOPT_URL, "http://website.org/login.php"); 
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "username=su&password=ch"); 
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, myfunc); 
     curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer); 
     curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); 
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //tell curl to output its progress 

      res = curl_easy_perform(curl); 

      CTOS_LCDTClearDisplay(); 

      char mai[30]; 
      char mai2[30]; 

      char *serverresponse = "bad"; 
      sprintf(mai2, "%s" , serverresponse); 
      sprintf(mai, "%s" , buffer); 

      if(mai2 == mai){ 
      CTOS_LCDTPrint("Invalid username"); 
      CTOS_KBDGet(&key); 
      }else{ 
       //loginname = buffer; 
       //mainusername = username; 
       CTOS_LCDTPrintXY(1, 1, "Login Success"); 
       CTOS_LCDTPrintXY(1, 2, "Welcome"); 
       CTOS_KBDGet(&key); 
       } 


    } 
} 
+1

구글은 C에서 문자열을 비교합니다. –

답변

0

mai2 및 마이 아래 코드는 문자 배열의 첫 번째 필드에 대한 포인터입니다. 이것들은 다른 배열이기 때문에 그것들의 주소는 물론 다릅니다. 당신은 내용을 비교하려는 따라서 당신은 두 개의 문자 배열이 같은 내용을 포함하는 경우 0이 될 것이다 strcmp

#include <string.h> 
strcmp("hello", "hello"); //0 

결과를 사용할 필요가 없습니다.

if (strcmp(mai, mai2) == 0) { 
    ... 
} 

-Hannes는

+0

그 문자열은 아마도 string.h 여야합니다. C++로 태그 지정 했음에도 불구하고 C를 사용하고있는 것처럼 보입니다. – Cubic

+0

감사합니다. 그러나 은 # –

+0

POS와 함께 사용할 수 없습니다 # Cubic. 감사. 편집 : string.h는 표준 C99이므로 모든 표준 컴파일러와 함께 컴파일해야합니다. –

1

당신이 C에 대한 그러나, C++에서 작품을 비교, 당신은 문자열을 비교 strcmp()를 사용해야합니다. 인수로 제공 한 두 개의 문자열에 동일한 내용이 포함되어 있으면 반환 값은 0이됩니다. 또한 대/소문자를 구분하지 않으려는 경우 stricmp()과 같이 필요할 때 다른 strcmp() 함수를 사용할 수 있습니다.