while writing a program in C how do I code a restart function for the program to re-initialize the program? What is the best way to do this as well?
Printable View
while writing a program in C how do I code a restart function for the program to re-initialize the program? What is the best way to do this as well?
Call main ? But I don't think that's a good idea.
Or simply, call the function that main calls first. For this, main, shouldn't have anything except the function called.
Maybe there are other ways, not sure.
A loop?
p.s. Never say those two words together.
p.p.s. The two words are not "a" and "loop." I am talking about the other two words which should not be mentioned together. The one that starts with a "c" and the one that starts with an "m."
If I had the code with me still I would have pasted it to show what it is that I am talking about
Well what use is it if you don't have the code anymore, how would you even fix it?
I think that I have a copy at home written in C++ that I would like to convert to C for my Final
Well you have two possibilities, since you should never (you know what)!
1. goto (the not good method)
and...
2. loop (the good way)
I suspect that the reason you want this is that if something goes wrong during the middle of the program, you can just start over. You can use a loop with continue.Code:do
{
the program;
} (don't stop till you get enough);
Could I do this:
Code:if (x != 'yes')
end;
else
continue;
Obviously you couldn't do exactly that, since 'yes' is meaningless and so is end. But you're trying very hard to do a loop without using a loop. I would recommend giving in and using a loop instead.
the question that is asked is asking the user for a stringed response thus, the 'yes' is a string input for the program to determine whether or not a restart is required.
1. A string literal is "like this"
2. you cannot compare strings with ==, != etc...
then how do i compare a string?
strcmp.