5
How to make a state machine in C, using decision commands (if
, else
) to go through a buffer received from the internet, byte by byte, in order to locate the first line breaks (\n\n
), and only then write the content? The socket part is already ok, only the state machine is missing
Basically with
switch case(estado)
– Franchesco
What have you tried? What difficulty are you having?
– hugomg
as @Earendul says: the most basic way is with
switch
: http://stackoverflow.com/a/1648098/25324 In this question you have many other ways of making state machines (see other answers).– pmg
The connection is made through a socket, and implemented in the HTTP 1.0 protocol. The program is command-line operated and compiled over Linux. It takes as parameter a complete URI and a file name, and then connects to the server, retrieves the page and saves to the informed file.
– Mazy999
Yes. The socket is ok. Missing only the part of the machine, to find and count these characters " r n r n". So I identify the beginning of the content, discharging all http header.
– Mazy999
It’s still unclear why you think you need a state machine. Why can’t you use something like
strtok
or even a simple tiefor
? Have you tried with any of these approaches?– Luiz Vieira
The "HTTP Header" consists of a few lines and an empty line break at the end. Each line has a string with its respective r n. And to be able to count these end-of-line characters + the r n r n of the empty line, you need a state machine, whatever way it is built. Thanks! Thanks for commenting.
– Mazy999
I had mentioned the
strtok
, but what will serve you is thestrstr
. See this example in the SOEN: http://stackoverflow.com/questions/18726077/split-string-through-strtok-in-c-language– Luiz Vieira