473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can Someone please help?

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
Aug 16 '06 #1
23 1476
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tiny Tim wrote:
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-----

Aug 16 '06 #2
Tiny Tim <ts*****@streamyx.comwrote:
[-- 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.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 16 '06 #3
>
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
Aug 16 '06 #4
Tiny Tim wrote:
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.

--
Simon.
Aug 16 '06 #5
Simon Biber wrote:
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 <STRONGtag was converted to asterisks for display on my screen.

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

--
Simon.
Aug 16 '06 #6
Christopher Benson-Manica <at***@otaku.freeshell.orgwrote:
void Compute ; /*function prototype*/
void Compute(); /* note parentheses */
Er, void Compute( void ), per Lew's post. D'oh!

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 16 '06 #7

"Christopher Benson-Manica" <at***@otaku.freeshell.orgwrote in message
news:eb*********@chessie.cirr.com...
Tiny Tim <ts*****@streamyx.comwrote:
>[-- 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
Aug 16 '06 #8
In article <44**********@news.peopletelecom.com.au>,
Simon Biber <ne**@ralmin.ccwrote:
>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
Aug 16 '06 #9
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
<STRONGtag was converted to asterisks for display on my screen.

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

--
Simon.
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
Aug 16 '06 #10
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.

--
Simon.

Thanks Simon,
I got it already.
Rgds,
Tim.
Aug 16 '06 #11
Tiny Tim wrote:
>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
<STRONGtag 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.
Tools -Options -Send -News Sending Format -Plain Text -OK

--
Simon.
Aug 16 '06 #12
Tiny Tim <ts*****@streamyx.comwrote:
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.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 16 '06 #13
"Lew Pitcher" <lp******@sympatico.cawrites:
Tiny Tim wrote:
>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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 16 '06 #14
"Tiny Tim" <ts*****@streamyx.comwrites:
"Christopher Benson-Manica" <at***@otaku.freeshell.orgwrote in message
news:eb*********@chessie.cirr.com...
>Tiny Tim <ts*****@streamyx.comwrote:
>>[-- 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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 16 '06 #15
Tools -Options -Send -News Sending Format -Plain Text -OK
>
--
Simon.
Thank you Simon.
I 've got it. I have set it up.
Thanks for your help.
Rgds,
Tim
Aug 17 '06 #16
Tiny Tim wrote:
"Christopher Benson-Manica" <at***@otaku.freeshell.orgwrote:
>Tiny Tim <ts*****@streamyx.comwrote:
>>[-- 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.

--
"I support the Red Sox and any team that beats the Yankees"
"Any baby snookums can be a Yankee fan, it takes real moral
fiber to be a Red Sox fan" - "I listened to Toronto come back
from 3:0 in '42, I watched Boston come back from 3:0 in '04"
Aug 17 '06 #17
Tiny Tim wrote:
>
Part 1.1 Type: Plain Text (text/plain)
Encoding: quoted-printable
Please do not use mime or html in newsgroups.

--
"I support the Red Sox and any team that beats the Yankees"
"Any baby snookums can be a Yankee fan, it takes real moral
fiber to be a Red Sox fan" - "I listened to Toronto come back
from 3:0 in '42, I watched Boston come back from 3:0 in '04"
Aug 17 '06 #18
CBFalconer <cb********@yahoo.comwrites:
Tiny Tim wrote:
>"Christopher Benson-Manica" <at***@otaku.freeshell.orgwrote:
>>Tiny Tim <ts*****@streamyx.comwrote:

[-- 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).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 17 '06 #19
Keith Thompson wrote:
"Lew Pitcher" <lp******@sympatico.cawrites:
Tiny Tim wrote:
<snip>
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.
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
mf*****@sbcglobal.net

Aug 17 '06 #20
#include <stdio.h>

void Compute(void) ; /*function prototype*/

int main ()
{ Compute(); /*function call*/

getchar();
return 0 ;
}
void Compute(void)
{
printf ("Hello");
return ;
}

This could be executed and get the results you want. But I do not know why

#include <stdio.h>
void Compute() ; /*function prototype*/

int main ()
{ Compute; /*function call*/

getchar();
return 0 ;
}
void Compute()
{
printf ("Hello");
return 0;
}

could be executed and pass my complier.
"Tiny Tim" <ts*****@streamyx.com??????:44**********@news.tm.n et.my...
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
Aug 17 '06 #21
Chen Shusheng <ly*******@hotmail.tomwrote:
This could be executed and get the results you want. But I do not know why
int main ()
{ Compute; /*function call*/
Presumably this is what is puzzling you. As Keith noted elsethread,
Compute in this case is equivalent to a pointer to the function,
making it a pointless but legal statement.

Two general notes:

1) Figure out how to tell LookOutExpress to prepend the text you are
replying to with the open carets that you see in this post; it makes
it infinitely easier to determine who said what.

2) Your reply should go below the text you are replying to, as I have
done in this post.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 17 '06 #22
"Mark F. Haigh" <mf*****@sbcglobal.netwrites:
Keith Thompson wrote:
[...]
>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.
Possibly, but Perl isn't the only language in which a function name
without parentheses can be a call to the function (if the function
takes no arguments). In fact, C is somewhat unusual in this regard,
at least in my experience (necessarily so because the name of a
function *without* parentheses as the address of the function,
something that many other languages don't have).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 17 '06 #23
Keith Thompson wrote:
"Mark F. Haigh" <mf*****@sbcglobal.netwrites:
Keith Thompson wrote:
[...]
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.

Possibly, but Perl isn't the only language in which a function name
without parentheses can be a call to the function (if the function
takes no arguments). In fact, C is somewhat unusual in this regard,
at least in my experience (necessarily so because the name of a
function *without* parentheses as the address of the function,
something that many other languages don't have).
I was just thinking out loud, trying to figure out where this
particular mistake likely originated from, if anywhere. I was thinking
someone familiar with Unix-isms might think along the lines:

--- sh ---
#!/bin/sh

Compute() {
printf "Hello, World\n";
return;
}

Compute;
exit 0;

--- perl ---
#!/usr/bin/perl -w

sub Compute {
printf "Hello, World\n";
return;
}

Compute;
exit 0;

--- And therefore C (formatted like perl) would be: ---

void Compute(void) {
printf("Hello, World!\n");
return;
}

int main(void) {
Compute; /* bzzt */
return 0;
}
Then I thought, hell, with the kids and their blogs these days it's
probably a mod_perl-er dipping his toe in the C end of the pool.

All in all, neither very interesting nor insightful. Ah well.
Mark F. Haigh
mf*****@sbcglobal.net

Aug 18 '06 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael Lauzon | last post by:
A while back, I had a program that I was working on, while taking Java in a Web Design & Development course -- this was back in 1999 -- not having the mindset of a programmer I failed that part of...
6
by: What-a-Tool | last post by:
I'm going out out of my mind trying to get this to work with no luck. The error message I get is at the bottom. Can someone please tell me what I'm doing wrong here. I've tried this a million...
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
8
by: Berhack | last post by:
I am not too familiar with C# interop so please help me out. I need to call the following C function (in a DLL): // this creates an array of strings // LPTSTR is just char * void C_Func(LPTSTR...
3
by: Marek | last post by:
Hello gurus! I wrote a code in VBS, that will check, that current user is in one from three groups. But i don't know how asimilate it with asp.net. This page will be a bridge between 2 - main...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
2
by: hassruby | last post by:
Can someone pls help me with some validation that im having a few technical problems with in my program. First of all, I will explain to you a little about what my program is suppose to do. It...
2
by: shblack | last post by:
Please can someone help me with this program. I am in a JAVA programming class and I am having a heck of a time. I am still having a problem with the basic concepts of JAVA but the teacher continues...
40
by: aslamhenry | last post by:
please key in any 5 digits number : 56789 and the ouput is 5678 9 567 89 56 789 5 6789
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.