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
  • please remember to use the < pre > and < /pre > tags for code - as it says in the instructions when you make a post!

    You are confusing your arrays and pointers - you need to re-read the section on strings in your 'C' textbook.

    The code you've shown won't compile, not least because you have defined the symbol 'string' twice:

    char *string[1] = {"OK"} ; //* string 1 = OK (text)
    defines 'string' as an array of 1 pointer;
    string[1] is a pointer to a char - in fact, the 1st char of "OK"
    char *string[2] = gets(arr);
    redefines 'string' as an array of 2 pointers!

    Take a look at the examples of strcmp and gets in the Manual, and that textbook.

Reply
  • please remember to use the < pre > and < /pre > tags for code - as it says in the instructions when you make a post!

    You are confusing your arrays and pointers - you need to re-read the section on strings in your 'C' textbook.

    The code you've shown won't compile, not least because you have defined the symbol 'string' twice:

    char *string[1] = {"OK"} ; //* string 1 = OK (text)
    defines 'string' as an array of 1 pointer;
    string[1] is a pointer to a char - in fact, the 1st char of "OK"
    char *string[2] = gets(arr);
    redefines 'string' as an array of 2 pointers!

    Take a look at the examples of strcmp and gets in the Manual, and that textbook.

Children
No data