OK I am just starting to make some simple programs and after I have made my main thing:
main()
{
printf("Whatever");
return 0;
}
How do I make something else like main?
Or do you only make 1 main()??
Printable View
OK I am just starting to make some simple programs and after I have made my main thing:
main()
{
printf("Whatever");
return 0;
}
How do I make something else like main?
Or do you only make 1 main()??
main is a function. You can only have one main. You can have as manu functions as you like. For example:
Your program starts at main. The first line calls the function PrintLine which takes nothing (void) and returns nothing, void. The first void means it returns nothing and the void in parenthesis means it takes nothing. The function, PrintLine, prints "Hello World" to the screen, moves to the next line and then returns to main. main then returns 0 and your program is over. Try a search on www.google.com for good C-Tutorials or check out my web page in my signature which contains some C-Tutorials.Code:void PrintLine(void){
printf("Hello World\n");
}
int main(void){
PrintLine();
return 0;
}
- Sean
Oh geez....
What do you mean? "main" is the *required* program entry point in any C program. Still, main is simply a function. So, yes, you can define different functions and so forth, but you do not simply create a bunch of main's!
You should ask a little more specific questions, and read some good starter books on C...
There is only one main (AFAIK). Other functions are defined outside main. A simple example of this would be;
If you put your functions before main, main can call them without issue.Code:
void whatever (void)
{
printf("Whatever");
}
int main (void)
{
whatever();
return 0;
}
I could explain lots more, but this would create more questions for you. I think you should really go back to the tutorials and work through them again.
Think of a problem you want to solve - but start small. For instance, if I asked you to write a program that calculates the volume of a cube, could you do it? Create a simple program to take a users input and outputs the result. This is how we all begin to write code. Step by step...
Tv is going, alot's going on, but here's something off my head quick like:Quote:
For instance, if I asked you to write a program that calculates the volume of a cube, could you do it?
It does the job, but could use work.Code:#include <stdio.h>
#include <conio.h>
#include <math.h>
int main ( void )
{
float Width;
float Height;
float Depth;
float Volume;
printf("Enter the width ( feet are being used ):\n$");
scanf("%f", &Width);
printf("\nEnter the height ( feet are being used ):\n$");
scanf("%f", &Height);
printf("\nEnter the width ( feet are being used ):\n$");
scanf("%f", &Depth);
Volume = Height * Width * Depth;
printf("\nThe cubic volume of this object is %f feet", Volume);
getch();
return 0;
}
Thanks a lot Shadow, I am just beginning this stuff but I actually understood most of that(except for some of the syntax but I am working on that).
So once again, thanks.