GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Feb-2004, 13:12
rbeierle rbeierle is offline
New Member
 
Join Date: Feb 2004
Posts: 6
rbeierle is on a distinguished road

New to C...need help calling functions


I'm taking an online Programming in C class, and my instructor is not very helpful. These are the assignment instructions...

Part I

Write an ANSI C program that displays the "Hello, World!" message to the console. – This part is to insure your compiler is working correctly.

Type in and compile the program as detailed in the lesson notes. I WANT YOU TO COMPILE FROM THE COMMAND LINE.


Part II

Modify your program as follows:

1. main() should call two functions ONLY.

a. Create a function called myinfo or identify which will display the following information.

Your name.
The course name and number
The Instructor’s name
The assignments Number
Today’s date (hint: use __DATE__ to get system date. DATE has two underscore before and after it)

b. Move your logic for HelloWorld into a function called displayHello

2. main() should call myinfo first, then displayHello

3. The main() function must return a value.

4. Turn in the source code and the executable in electronic format.


I have part I done, and I have myinfo done. My question is how do I get main() to call myinfo, then helloworld as well? I'm completely lost.
  #2  
Old 10-Feb-2004, 14:31
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi rbeierle. Welcome to these forums and to the wonderful world of C programming

First of all, you may want to read through this thread for a little explanation of functions.

Basically your entire program should be in a single file with your main() function at the bottom of the file.

To define a function us:
CPP / C++ / C Code:
void a_function(){
   printf("This is a function.\n");
}
the void in front of the function indicates that this function will not return a value.

Then in the same file to call the function, you would use:
CPP / C++ / C Code:
int main(){
   a_function();
 
   return(0);
}
Main is defined as an int which means that it should return an integer value. Thus the last line that returns a 0 to the calling process.

This should get you going I hope.
  #3  
Old 10-Feb-2004, 15:02
rbeierle rbeierle is offline
New Member
 
Join Date: Feb 2004
Posts: 6
rbeierle is on a distinguished road
ugh, thank you so much man. i don't know about this C stuff...it's driving me mad.

  #4  
Old 10-Feb-2004, 18:46
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by rbeierle
ugh, thank you so much man. i don't know about this C stuff...it's driving me mad.

Not a problem. I hope it helped. I'm a little biased but I think C is one of the greatest things you can learn for the computer. It may seem a little hard at first, but I think it really helps you to understand how a computer operates. In addition it will give you a great basis for other computer languages.

If you have any struggles or problems go ahead and post them as we will try to help you out (although we won't do your homework for you )

Good luck!
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need C++ help with functions EvilIce C++ Forum 2 01-Dec-2003 16:04
need help to define a class in C++ yannoush C++ Forum 7 09-Sep-2003 00:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.