help on main()

Hi,
I have some problem with code the main(). The program is for communicating with a micro controller through the SCI port.

the main() is supposed to do:
Main Program. 1. Set up The message is: “ The main function ”

2. Write the message to the screen.

3. Wait approximately 1 second. with wait_sec() function

4. Check to see if there is an input character waiting to be read. If not, loop back to b. above.

5. If there is an input character waiting, read it in, echoing it, and then output a CR and LF (using CRLF()).
• If the character is “N” or “n”, call MsgIn() to read in a new message that immediately replaces the previous message being printed once per second.
• If the character is “X” or “x”, exit the program.
• If the character is something else, just ignore it.6. Loop back to 2. above.

Note that MsgIn(char inData[], unsigned int length) that reads in messages received at the SCI input. inData is the address of an input array prepared to receive input data, and the length of the array, and one output argument, the actual received message length.

Code:

void main(void) {
/* put your own code here */
const data[]="The main function";
char input;
InitSci(5); /* initialize SCI post*/
message_out(data); /*display message*/
wait_sec();/*1 sec wait*/
while (1){ /*loop back until the character is ready to be read*/
message_out(data);
if(IntStatusSCI()){/*IntStatusSCI() returns true if a character available to be read; returns false if not. */
break;}/*break if the character is read*/
}
input=GetSci();/*input character into SCI port*/
CRLF();/*write out a CR and LF*/
if(( input=='N')| (input=='n'))
MsgIn(); /*read the message*/
else if( (input=='X')| (input=='n'))
exit;
else{/*ignore it code*/}
}/*end main*/

I have problem understanding the main does especially when it reads the new message and loops back.

My second issue is the function MsgIn(). How do we know the length of the new message?

>My second issue is the function MsgIn(). How do we know the length of the new message?
And this is answered above:

Originally Posted by braddy

Note that MsgIn(char inData[], unsigned int length) that reads in messages received at the SCI input. inData is the address of an input array prepared to receive input data, and the length of the array, and one output argument, the actual received message length.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

Beside what you mention, does my main follows the steps 1-7?
I am not very sure it does. I need a feedback on it please?

It's hard to say because of this:
>4. Check to see if there is an input character waiting to be read. If not, loop back to b. above.
And there is no b to loop back to. Also in step 6, I don't see where you loop back to 2.

the Lab is closed now and I dont have code warrior on my machine. when I try to dowload it, it crashes.

Mmm, well, you're not going to learn too much if you don't have a compiler on your machine that you can experiment with.

I take it you're using Mac OS? Code warrior runs on systems besides Macs, but I don't think it's widely used outside of the Mac world.

So, when does it crash? Does the download crash? the installer? the program? the compile?

dwk

Seek and ye shall find. quaere et invenies.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell