home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

could someone look at this....

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1575
Discussions: 200,988, Posts: 2,379,871, Members: 246,358
Old January 19th, 2003, 11:23 PM   Digg it!   #1 (permalink)
Member
 
couch potato's Avatar
 
Join Date: Oct 2002
Location: Salem, Oregon
Posts: 480
could someone look at this....

im really new to C still, but i tried to write this program:

#include "main.h"
#include <stdio.h>

main()
{
#include "main.h"

char first[15], last[15];
float weight;
int age;

printf("Please enter your first name: ");
scanf(" %s", first);
printf("Now enter your last name: ");
scanf(" %s", last);

printf(" Now enter your age please: ");
scanf(" %d", &age);

printf(" Now enter your weight: ");
scanf(" %f", &weight);

printf(" %s %s\n", first, last);
printf("Weight: %f", weight);
printf("Age: %d", age);
return 0;

}


the main.h header file contains:

main()
{
printf("Hello");
}




i just read about header files, and im still a little confused. the compiler doesnt like this, and i know its because of me. can anyone help me correct this little program?
couch potato is offline   Reply With Quote
Old January 20th, 2003, 12:54 AM     #2 (permalink)
Member
 
Join Date: Feb 2002
Posts: 161
In this case, you don't need the file main.h at all. Just remove it, and delete both '#include "main.h"' lines.

In general, you use header files when you need to access functions or variables which exist in another source file (that is, another .c file). They have other uses, of course, but this is the simplest. So for example, if you wanted a function to print 'Hello', you might create a source file called hello.c, containing the following function:

void PrintHello(void)
{
printf("Hello!\n");
}

You would then create a header file, hello.h, containing the definition of the PrintHello function:

void PrintHello(void);

By including this file from your main source file (say, main.c), you will now be able to use the PrintHello() function, even though it exists in a separate source file.
Martee is offline   Reply With Quote
Old January 20th, 2003, 02:11 PM     #3 (permalink)
Member
 
couch potato's Avatar
 
Join Date: Oct 2002
Location: Salem, Oregon
Posts: 480
ok, thanks. that helps a lot. im not sure if i should ask, but why put void before the name of the function? just wondering, as the book im learning from doesnt talk about that yet
couch potato is offline   Reply With Quote
Old January 20th, 2003, 11:25 PM     #4 (permalink)
Member
 
Join Date: Feb 2002
Posts: 161
You put void in front of the function to indicate that it doesn't return a value to the caller. If you wanted the function to return, say, an int, then you would put an int in front of it in place of the void, and add a statement like 'return 0;'.
Martee is offline   Reply With Quote
Old January 22nd, 2003, 12:05 AM     #5 (permalink)
Member
 
couch potato's Avatar
 
Join Date: Oct 2002
Location: Salem, Oregon
Posts: 480
hmm, a little confusing. thats ok, hopefully ill learn it later on
couch potato is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3067)
Charges against non-tippers dropped.. (20)
Health Care Rationing (11)
Delete an OS (17)
Nvidia GTX 260 problem (10)
Laptop with wireless problem. (12)
windows vista security holes (19)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
Point and Shoot Camera Suggestions. (8)
windows 7 problem (7)
[F@H SPAM 11/16/09] ! 1/2 months to.. (39)
Internet Lost (5)
Recent Discussions
Looking for new motherboard (1)
soundmon.exe (8)
Jedi Academy Problem (3)
Desktop Calendar Application (1)
Can a page file be "too big".. (1)
Nvidia GTX 260 problem (10)
Point and Shoot Camera Suggestions. (8)
Size after cutting 700Mb file is 2.5 .. (0)
Delete an OS (17)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (39)
windows vista security holes (19)
updating BIOS via winflash, claims fi.. (1)
New Server Configuration Suggestions (0)
cheap gaming laptop? (12)
Unallocated Space (2)
help me pls laptop just stopped worki.. (1)
C# + LINQ Help (7)
Dynex DX E-402 (3)
EVGA 9800 gtx help with finding a goo.. (12)
Multiple Restarts Required at Boot (5)
cell phone won't work (0)
Is the PSU I received dead? (15)
Can't open Word (12)
Steam ID's, Gamertags etc... (4)
Games, Cables, PCI cards, and more fo.. (6)


All times are GMT -4. The time now is 07:26 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28