0

How to read and compare strings from dynamic output console in C Programming?

Consider, you will get one output at a time. You need to consider the output from a Program as an input to other program function. The example output of the Program 1 as follows,

A123#345H5KGH3***STATE***GETRUNOMMUNICATION5619***CONNECTED***HIEDSAKNFH***OK***

enter image description here

I need to get the statement STATE:CONNECTEDOK if this statement present in the output console, then the next program(function) will start.

Note:

  1. I am getting one output at a time

  2. Consider the first output as "A" the next one will be "A1" and the following output as "A12".

  3. I thought to use array to store values, but the output range( unlimited) makes it very lengthy and difficult to configure before hand ,since the length of the array is unknown.

  4. If the specified statement appears in the output console, then it should prompt some message.

  5. No spaces in between the two continues outputs.

I thought to use strings, so my question are as follows,

  1. How to read the string from output console, when the length of the string is unknown?

  2. What function I need to use to perform the comparison ( I already know the statement "STATE:CONNECTEDOK") with unknown length of output?

  3. How to store the output data, when the range or length is unknown?

Thank you.

1
  • Execute the first program generating the STATE:CONNECTEDOK message in the context of the second using something like execl(). Then capture the output from it as you would any input from the user. Commented Apr 3, 2013 at 12:45

1 Answer 1

1

Assuming you don't mean that you want to identify the data graphically from the actual console window, but instead that you can pipe the data to your program, I think the best bet is to use a state machine, namely an "acceptor".

You simply read a character at a time, and feed it into the state machine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, this is the expected answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.