-
I have 2 Q's for you all
Okey Question 1:
What is the deal with
Code:
printf("wang\n");
printf("wang\n");
and...
Code:
printf("wang\n"
"wang\n");
if you have more text to display which is best to use?
just a small one.
Question 2:
If you would like to have a look at my code in general, its not too big, see if you find anything im doing wrong, as it starts to get bigger i dont want messy code etc, any thoughts let them rip. keep in mind its no where nere done.
code
-
code:
printf("wang\n");
printf("wang\n");
and...
code:
printf("wang\n"
"wang\n");
I think you mean.
[code]
printf("wang\nwang\n");
printf("wang\n" "wang\n"); won't work I wouldn't think.
[\code]
That's just to simplify code and reduce space really. Two printf statements for two seperate lines can be avoided by the \n which means a newline.
-
>printf("wang\n" "wang\n"); won't work I wouldn't think.
as far as i knew
printf("wang\n" "wang\n");
and
printf("wang\n"
"wang\n");
were the same... white space is nothing. I know what \n is.
I was talking more along the lines of the size of the .exe made, does it make a difference? speed wise etc. Look at my code for a better example of what i mean.
-
(1) It usually doesn't matter. Most thinks most make are hardly mission critical, so it really doesn't matter here. However, you've got two schools of thought:
(1a) Write readable code first and foremost. If it's clearer to use two statements, do so. If it looks better with a single call, go that route.
(1b) Write efficient code next. Ideally, your code won't be horribly inefficient from its initial design, so you won't really need to focus on optimizing it with questions such as the above. However, if you want to know, it's less overhead to do a single function call than it is to have two. So the second of the two would be better.
When in doubt, focus on readability.
(2) There are a few points I'll note at a glance:
(2a) Why the global variable?
int Answer = 0;
(2b) Never call 'main':
Code:
/* About the program */
int About( void )
{
printf ( "\nRobinson's Quizzes -- 1.0\n\n"
"Robinson's Quizzes was created by Daniel Robinson\n"
"This program was made for my Year 12 Major Project.\n"
"Please send any requests or bugs to {email addy}\n\n" );
system ("PAUSE");
main();
return 1;
}
You are not able to do this with a C99 compiler. It is no longer valid. It's not a good idea anyway, because of the stack overhead you'll run into with recursion.
You call main in a bunch of functions. You should just be returning to the main function and continuing in your loop.
[edit]Removed your email addy from the code snippet to save you from getting spammed to death.[/edit]
Quzah.
-
Quote:
Originally posted by Twiggy
I think you mean.
Code:
printf("wang\nwang\n");
printf("wang\n" "wang\n"); won't work I wouldn't think.
I fixed your code tag. But no, both pieces of code are identical. The two strings will be concatenated as one. Since they are not seperated by a ',' in this instance, they are considered as a single argument. As such, like all strings like this, they're merged into a single string. The end result is both of those two printf statements are the same.
Quzah.
-
thanks for your help quzah, an extra function fixed the problem of calling main(). I use Borland C++ Builder 6, i thought it would have used a C99 compiler... Oh well.
Thanks again.
Cheers.