you will have to be a tad bit more specific because there are millions of programs.:mrgreen:
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
you will have to be a tad bit more specific because there are millions of programs.:mrgreen:
That's just mean...
Here's a program for you:
#include <stdio.h>
int main()
{
return 0;
}
I'm joking as you might have noticed :mrgreen:
Ancient Dragon is right, what do you want and what have you made so far?
Niek
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
that's in fact an excellent program. It compiles, it runs, and all without errors.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
With the only problem being the wrong prototype of main....:D
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
I see nothing wrong with his main() -- argc and argv parameters are optional.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
In C, when a function defination or declaration is followed by an empty pair of parentheses it means that zero or more parameters. So main when written as int main( ) in C can stand for int main( int, int, int ) or int main( void, void ) or whatever, whereas the standard specifically says that the prototype of main can only be either int main( void ) or int main( int argc, char** argv ) . Hence the explicit void is required in case of pure C programs.
Whereas in C++ when a function defination or declaration is followed by an empty pair of parentheses it means it does not take any argument i.e. void . Hence the void can be safely omitted in C++.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
An extract from Google Groups:
A C program is not required to work right if its main function does not have one of these two types:
int main(void) { /*...*/ }
int main(int argc, char **argv) { /*...*/ }
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
You guys lost me at the "Hello". :)
But since you seem to be very knowledgeable (I know you are) I have a question for you:
In C programming there's a way I could see what is in the stdin buffer?. I always hear about
stdin buffer, how big is this buffer?.
Another another question that is bothering me for sometime, if I would like to construct
a function I have only the C Standard Library functions to do that right?
for example if I want to create a function that read a caracter from stdin I have to use
getchar(),
Do you understand what I am asking?.
I would like to know how to make a getchar() function. Or better yet, what makes getchar()
behind the scene work, How is it that can read a character?.
I hope you can show me some words of wisdom.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
@ Ravalon
It's hard to be humble when you're as gifted as I am at pretending to be an expert.
I love the your quote at the end.
You're alright, and I don't care what they say! :)
I'm going to bookmark your answer for futher study. I'm barely learning about pointers and you use some.
By the way, I noticed that you usedFILE* with the * close to the word FILE which I understand that it is a structure. That
reminded me that I have seen instances with the word followed by a *,
Is that different that something like
char *p?.
Does the place of the * makes it a different thing that I haven't encounter in the pointer lession yet?.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
Is it just me, or did this thread suddenly take a strange turn? We went from someone wanting programs to nitty-gritty details of the C89/C99 to reading input streams! Needless to say, the OP definitely should have been clearer when asking his/her question and then maybe this thread wouldn't have gotten so off-topic. ;)
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Is it just me, or did this thread suddenly take a strange turn?
OK. sorry I won't ask any more questions in this post.
Thank you very much, is great to get answers sometimes. I hope someday I will be good enough to help others with answers.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
OK. sorry I won't ask any more questions in this post.
Thank you very much, is great to get answers sometimes. I hope someday I will be good enough to help others with answers.
Persistance is the key. If you never give up, I can assure you that you can become a C/C++ expert.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Only for a declaration. For a definition an empty pair of parentheses really does mean zero parameters.
I don't think so, atleast not in C -- take a look at this program and compile it using a C compiler.
int add1( )
{
return 1 ;
}
int add2( void )
{
return 1 ;
}
int main( void )
{
int sum1 = 0 ;
int sum2 = 0 ;
sum1 = add1( 1, 2, 3 ) ; // silently ignored...
sum2 = add2( 1, 2, 3 ) ; // raises an error
return 0 ;
}
An extract from C99 standard clause 6.5.2.2 If the expression that denotes the called function has a type that includes a prototype, the number of arguments shall agree with the number of parameters. Each argument shall have a type such that its value may be assigned to an object with the unqualified version of the type of its corresponding parameter. So if you use int main( ) you can very well do something like:
int main( )
{
if( 0 )
main( 'a', 'b', 'x', "more crap" ) ;
return 0 ;
}
...which actually shouldn't be allowed and doesn't make sense either.
Thus the only correct way of using main is :int main( void )
int main( int argc, char* argv[] )
Anything else is implementation defined and though it will may get documented by the compiler writer, but since they are optional ,portable code won't use them.
But there's no point in splitting hairs because this stuff is mostly academic fodder for pedantic programmers.
Yeah, but its always fun clobbering someone or getting clobbered to unconciousness with these blasted standards....;) But since you seem to be very knowledgeable (I know you are) You're alright, and I don't care what they say!
Yeah, I guess it comes from years of experience -- did I ever mention that Raye teaches his kids C++ in free time (yeah he is that old)....:twisted:We went from someone wanting programs to nitty-gritty details of the C89/C99 to reading input streams!Welcome to the world of thread hijackers....;)
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734