Can Someone please help?

T

Tiny Tim

I am new C program student.

I wonder can we write a program in C that just trigger its function to do a certain action ?
In this case, I have a program but it is not working.
What I want is for the function to print "Hello". No passing of values to or from the function.
What is the correct way to write the program?

#include <stdio.h>

void Compute ; /*function prototype*/

int main ()
{ Compute; /*function call*/
return 0 ;
}
void Compute
{
printf ("Hello");
return ;
}

Thank you
Tim
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Tiny said:
I am new C program student.

I wonder can we write a program in C that just trigger its function to do a certain action ?
In this case, I have a program but it is not working.
What I want is for the function to print "Hello". No passing of values to or from the function.
What is the correct way to write the program?

#include <stdio.h>

void Compute ; /*function prototype*/

Nope.

That's not a function prototype.

However,

void Compute(void);

is a function prototype.

Notice the difference? A function (prototype or not) has a list of zero
or more parameters, and is designated as a function by the presence of
the trailing bracketed parameter list.
int main ()
{ Compute; /*function call*/

Nope. That's not a function call. At best (had Compute not been
declared as void), that would be an expression involving a single
variable.

If you wanted a function call, you should have coded

Compute();

return 0 ;
}
void Compute

Requires a parameter list of zero or more parameters

Should have been

void Compute() /* or perhaps void Compute(void) */
{
printf ("Hello");
return ;
}

Thank you
Tim

HTH

- --
Lew Pitcher



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFE4zjNagVFX4UWr64RAuR2AJ9YfRph/ZbwBG8nH7qOziTqddV8JQCfXMte
n20INoD8+uggOY5YzXzwdWA=
=+C8Q
-----END PGP SIGNATURE-----
 
C

Christopher Benson-Manica

Tiny Tim said:
[-- text/plain, encoding quoted-printable, charset: iso-8859-1, 25 lines --]

Please don't post encoded articles, if you can help it.
#include <stdio.h>
void Compute ; /*function prototype*/

void Compute(); /* note parentheses */
int main ()
{
Compute; /*function call*/ Compute(); /* again */
return 0 ;
}
void Compute
void Compute() /* and again */
{
printf ("Hello");
return ;
}

I'd advise procuring a C book, preferably "The C Programming
Language", as soon as possible.
 
T

Tiny Tim

Nope. That's not a function call. At best (had Compute not been
declared as void), that would be an expression involving a single
variable.

If you wanted a function call, you should have coded

Compute();

- --
Lew Pitcher

Thank you Mr. Lew Pitcher
for such a superspeed reply.
I got my problem solved already.
Now I can move on.
Thanks again
Rgds,
Tim
 
S

Simon Biber

Tiny said:
I am new C program student.

I wonder can we write a program in C that just trigger its function to do a
certain action ?
In this case, I have a program but it is not working.
What I want is for the function to print "Hello". No passing of values to or
from the function.
What is the correct way to write the program?

#include <stdio.h>

void Compute ; */*function prototype*/*

This is not a function prototype.

To declare a function, you must put parentheses after the function name.
The declaration above tries to declare a variable of type void, which is
not allowed.

Make it:
void Compute(); /* function declaration without prototype */
or
void Compute(void); /* function declaration with prototype */

Comments start with /* and end with */. You have added two extra
asterisks to the program that do not belong.
int main ()
{ Compute; */*function call*/

Your statement above merely evaluates Compute and does nothing. It does
not call it.

To call a function, you must put parentheses after the function name:
Compute();

There is also an extra asterisk in the line above.
* return 0 ;

There is an extra asterisk in the line above.
}
void Compute

A function definition must have parentheses after the function name.
This is simply a syntax error.
{
printf ("Hello");
return ;

A return statement is not necessary in a function that returns void, but
it does no harm.
}
Thank you
Tim

You're welcome.
 
S

Simon Biber

Simon said:
Tiny Tim wrote: [...]
void Compute ; */*function prototype*/*
[...]
Comments start with /* and end with */. You have added two extra
asterisks to the program that do not belong.

It appears that the extra asterisks were not in your original post but
were added by my Usenet client. They were added because you committed
the cardinal sin of posting to Usenet in HTML, and bolded the comments.
The <STRONG> tag was converted to asterisks for display on my screen.

In future, you can avoid this problem by not posting HTML to newsgroups!
 
T

Tiny Tim

Christopher Benson-Manica said:
Tiny Tim said:
[-- text/plain, encoding quoted-printable, charset: iso-8859-1, 25
lines --]

Please don't post encoded articles, if you can help it.


Dear Christopher,
Can you kindly teach/guide me how to avoid encoded articles in my Windows
XP running Outlook Express, by switching html format to text format?

Thanks
Rgds,
Tim
 
T

Tiny Tim

A function definition must have parentheses after the function name.
This is simply a syntax error.


A return statement is not necessary in a function that returns void, but
it does no harm.


You're welcome.


Thanks Simon,
I got it already.
Rgds,
Tim.
 
R

Richard Tobin

Simon Biber said:
It appears that the extra asterisks were not in your original post but
were added by my Usenet client. They were added because you committed
the cardinal sin of posting to Usenet in HTML, and bolded the comments.

He posted it in both plain text and HTML. Posting in HTML is
certainly silly, but it's even sillier of your newsreader to show you
the HTML-converted-to-plain-text and not the plain text.

-- Richard
 
T

Tiny Tim

It appears that the extra asterisks were not in your original post but
were added by my Usenet client. They were added because you committed the
cardinal sin of posting to Usenet in HTML, and bolded the comments. The
<STRONG> tag was converted to asterisks for display on my screen.

In future, you can avoid this problem by not posting HTML to newsgroups!

Sorry, Simon,
Do you know how to switch HTML format to TEXT format on my WindowsXP (
running Outlook Express)?
Hope to solve the HTML posting problem.
Thanks
RGds,
Tim
 
S

Simon Biber

Tiny said:
Sorry, Simon,
Do you know how to switch HTML format to TEXT format on my WindowsXP (
running Outlook Express)?
Hope to solve the HTML posting problem.

Tools -> Options -> Send -> News Sending Format -> Plain Text -> OK
 
C

Christopher Benson-Manica

Tiny Tim said:
Can you kindly teach/guide me how to avoid encoded articles in my Windows
XP running Outlook Express, by switching html format to text format?

You avoided it with this post, so it seems that whatever setting you
changed worked.
 
K

Keith Thompson

Lew Pitcher said:
Tiny said:
I am new C program student. [...]
void Compute ; /*function prototype*/

Nope.

That's not a function prototype.

However,

void Compute(void);

is a function prototype.
[...]
int main ()
{ Compute; /*function call*/

Nope. That's not a function call. At best (had Compute not been
declared as void), that would be an expression involving a single
variable.

If you wanted a function call, you should have coded

Compute();

Yes, but "Compute;" by itself (if Compute() is properly declared as a
function) is a valid (but useless) statement. The name of a function,
regardless of what it returns or what arguments it takes, is (usually)
converted to a pointer to the function. "Compute" by itself evaluates
to the address of the Compute function. Add a semicolon, and it's an
expression statement that evaluates the expression and discards the
result. Net effect: nothing happens.
 
K

Keith Thompson

Tiny Tim said:
Christopher Benson-Manica said:
Tiny Tim said:
[-- text/plain, encoding quoted-printable, charset: iso-8859-1, 25
lines --]

Please don't post encoded articles, if you can help it.

Can you kindly teach/guide me how to avoid encoded articles in my Windows
XP running Outlook Express, by switching html format to text format?

Yes, you want text format. Consult the documentation for Outlook
Express to find out how to do that.
 
T

Tiny Tim

Tools -> Options -> Send -> News Sending Format -> Plain Text -> OK
Thank you Simon.
I 've got it. I have set it up.
Thanks for your help.
Rgds,
Tim
 
C

CBFalconer

Tiny said:
Christopher Benson-Manica said:
Tiny Tim said:
[-- text/plain, encoding quoted-printable, charset: iso-8859-1,
25 lines --]

Please don't post encoded articles, if you can help it.

Can you kindly teach/guide me how to avoid encoded articles in
my Windows XP running Outlook Express, by switching html format
to text format?

Get rid of Outlook Express. You can use Thunderbird or Netscape
4.7x, or many others, all less buggy.
 
K

Keith Thompson

CBFalconer said:
Tiny said:
Christopher Benson-Manica said:
[-- text/plain, encoding quoted-printable, charset: iso-8859-1,
25 lines --]

Please don't post encoded articles, if you can help it.

Can you kindly teach/guide me how to avoid encoded articles in
my Windows XP running Outlook Express, by switching html format
to text format?

Get rid of Outlook Express. You can use Thunderbird or Netscape
4.7x, or many others, all less buggy.

This may be good advice on its own merits, but Outlook Express can be
configured to post plain text (as the OP has already found).
 
M

Mark F. Haigh

Keith said:
Yes, but "Compute;" by itself (if Compute() is properly declared as a
function) is a valid (but useless) statement. The name of a function,
regardless of what it returns or what arguments it takes, is (usually)
converted to a pointer to the function. "Compute" by itself evaluates
to the address of the Compute function. Add a semicolon, and it's an
expression statement that evaluates the expression and discards the
result. Net effect: nothing happens.

I wonder if the OP had a little perl experience? A perl programmer
might think you can ditch the (), as is legal in perl. Interesting.


Mark F. Haigh
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top