/* I was reading through my C for Dummies book and I found the right answer. Simple, don't know why I didn't think of that. Anyway, for people who were wondering, the correct code would be as follows: */
// Our project name will be called "CExampleProject".
#include <stdio.h> // Why do we include that? That's a file filled with APIs we need!
int main() // This is what's going to run as the process first loads.
{
char option; // char means character, so it's a phrase with characters. option is our character, that's what we defined.
printf("Please type YES to continue, or NO to terminate the program.\n"); /* When we use print, in printf, it doesn't exactly mean printing from a printer. Definition: an indentation or mark left on a surface or soft substance by pressure. <--- That's basically saying that print means to mark. The "\n" that we use at the end, is letting it know that something different is going to happen. The "\" alerts it and prepares it for a unconventional phrase, such as a letter that represents a key not able to be keystroked. The "n" means the return, or enter key. */
scanf("%s" option); // The %s is for a text field, or something similar to a text field to also be included in the action.
if (option=='YES') { /* That's our condition, that says right there that if our option field, or our imaginary field, has the text "YES", as the only text in the field, then it will continue on to the statement listed next. */
printf("Okay, you chose to continue.\n");
// And then of course you can insert some more code right here.
}
if (option=='NO') { /* Now we're saying that if the only text in option is "NO", then we are going to run the statement that follows. */
printf("Okay, you chose to quit. Exiting in 5 seconds.\n");
exit(5); /* the exit(); function tells the process or application to terminate. in the parentheses is where you would put the duration before it finally executes. */
}
else { /* else means whatever else happens, something not specified. Above we have targeted items, here is for everything else. */
printf("Invalid argument.\n");
system("./CExampleProject"); // We're just going to pretend you've already cd into the folder holding the file.
// What we did here, is we made it run the whole process over again. Kind of like a loop.
// And yes, I know... system(); isn't always the best way to run shell commands... :p
}
return(0); // Always do this at the end of your code!! It's very important!!
}
/* And now our code is finished... Now, Makefiles are another thing! :p But make sure to save this as CExampleProject.c */
// We have not made the executable yet... this is just the source file.
// This was intended to be done on a Mac.
answered
Sep 24 '10 at 23:47
AppleHack23
(suspended)