Hello all,
I am supporting an application that I did not program. I also am only a beginner with C programming, so my understanding is limited. We have had some unexpected results from the program that I need to fix. Here is the first problem.
I am programming a PIC18 chip that runs a microcomputer. This microcomputer needs to respond to two distinct situations:
1. If the computer is reset using the master clear switch, it needs to go through the startup questions with the default answer of 'n'
2. If the computer is reset using the master clear switch, it needs to accept input from the keyboard to answer a series of questions, all the initial ones are y/n type questions.
Basically if the first y/n question is not answered, then the computer should assume it is a 'n' and move on. Here is the relevant code:
After the RS232 port has been opened
Code:
printf("Startup Event\r");
printf("would you like to perform a manual startup event (Y/N)? \r");
get_string(download_answer, 4);
if (isamoung(download_answer[0],"Yy")) {
//Ask the rest of the questions
//More code that is not relevant....
} else {
//This is an auto-startup event, set default variables
//More code that is not relevant....
}
The variable download_answer is not initialized when it is created. When the question "would you like to perform...."
appears on the screen, sometimes the first time we answer the question a 'y' or 'Y' response will still lead to the program treating the answer as not a 'y' or 'Y' and going to the auto startup event programming. If you reset the computer again, it always recognizes the 'y' or 'Y' response
My questions are:
1. Is this because the the download_answer variable is not initialized?
2. would initializing it to downoad_answer[0] = 'n'; be sufficient to avoid this problem, or do you think I have a bigger issue to deal with here in another portion of the code?
Thanks!
Brian