This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C167 reading/scanning input from GSM module from RS232

Hello,
I am a novice in C language and have been trying to find a method of reading/scanning input from GSM, then comparing it against a text (e.g OK or ERROR). Then if true set a break.

I have tried scanf with no avail. I have also tried reading string which works but am unsure how to compare with my text.Has anyone any advice with what function would be useful?

Any replies greatly appreciated.

Andy

Parents
  • I tried using the section of code below to read a string and then compare it. I get 3 warnings and this may be why I am not getting correct results. If i type ok press carriage return the result will be zero which is what I am looking for.

    If i type anything else it is not zero which is fine but when i then try to type OK it still gives error. Any ideas if this is due to warnings?

    I may try _getchar , is this a better method of getting input?

    {


    char arr[50];

    printf("Enter up to 50 characters, with spaces\n");
    gets(arr);

    printf("\nInput read into array was:\n");
    puts(arr);
    }
    {
    char *string[1] = {"OK"} ;
    int result;
    char *arr = puts(arr);
    result = strcmp(string[1], puts(arr));
    printf("Result comparing OK to input is %d\n", result);
    }

Reply
  • I tried using the section of code below to read a string and then compare it. I get 3 warnings and this may be why I am not getting correct results. If i type ok press carriage return the result will be zero which is what I am looking for.

    If i type anything else it is not zero which is fine but when i then try to type OK it still gives error. Any ideas if this is due to warnings?

    I may try _getchar , is this a better method of getting input?

    {


    char arr[50];

    printf("Enter up to 50 characters, with spaces\n");
    gets(arr);

    printf("\nInput read into array was:\n");
    puts(arr);
    }
    {
    char *string[1] = {"OK"} ;
    int result;
    char *arr = puts(arr);
    result = strcmp(string[1], puts(arr));
    printf("Result comparing OK to input is %d\n", result);
    }

Children