LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-31-2005, 12:52 AM   #1
hk_michael
LQ Newbie
 
Registered: Oct 2004
Posts: 22

Rep: Reputation: 15
2 programming questions


Hi all!
My project is required to do the thing now:
the program continues to run until I press Ctrl+C to break it as the PC is acted as server. So, I wish to know how can I do so that such effect can be done?
Also, as my progmra has man many lines, in order to let my supervisor and even me to look clearer, I wish to break the program into few files. But my C profgram does not contain class. So, I wish to know that how can I seperate the program into few files and then create a make up file so that I can compile all files together?
Thanks
 
Old 01-31-2005, 01:36 AM   #2
Libu
Member
 
Registered: Oct 2003
Location: Chennai
Distribution: Slackware 12.1
Posts: 165

Rep: Reputation: 36
Quote:
Also, as my progmra has man many lines, in order to let my supervisor
and even me to look clearer, I wish to break the program into few files. But my
C profgram does not contain class. So, I wish to know that how can I seperate the
program into few files and then create a make up file so that I can compile all files
together?
What i do is, create a header file which contains the function prototypes of all the functions that Iam using in my project and then separate the function definition in separate .c files.

For e.g. if u have fucntion prime_num(int) :
I would the following in the custom header file:

Code:
#include <stdio.h>
..
int prime_num(int) /*Function Decalaration*/
..
.
Then I would create a .c file prime_num.c:
Code:
#include "custom_headerfile"

int prime_num (int x) {
/*Function Definition*/
}
Ur main file would be something like this:
Code:
#include....
#include "custom_headerfile"

int main () {
   int x;
.
.
prime_num(x);
..
..
}
As for makefiles, its quite simple actually. Hereis a good link
http://users.actcom.co.il/~choo/lupg...makefiles.html

Last edited by Libu; 01-31-2005 at 01:39 AM.
 
Old 01-31-2005, 10:01 AM   #3
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
if you program will be stopped by ctrl + C, then it can be a big infinit loop.

Code:
while (1)
{
}
This is how most servers are implemented.

As to make your program more readable/managable, you can pick out some "logical groups" of functions and put them in different file with .h and .c file. For examples, all the helper functions or functions that perform different parts of a complex calculation.
 
Old 01-31-2005, 02:35 PM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
> int prime_num(int) /*Function Decalaration*/
not that there's a missing semicolon ('int prime_num(int);').

also, you might want to look at the library function 'signal' (signal.h), SIGINT and SIGTERM.

Best of luck with your project,

Jonas
 
Old 02-01-2005, 01:02 AM   #5
Libu
Member
 
Registered: Oct 2003
Location: Chennai
Distribution: Slackware 12.1
Posts: 165

Rep: Reputation: 36
Oops )!! ya, jonaskoelker, I missed that !!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
questions about programming... efm Programming 12 11-29-2005 02:58 PM
HELP!!!! 5 questions about linux programming jormuocu Programming 4 01-30-2005 06:17 PM
Programming Questions/Poll name_in_use450 Programming 10 07-15-2004 09:09 PM
programming questions eboats Linux - General 19 10-22-2001 06:15 PM
programming questions eboats Programming 4 10-17-2001 03:15 AM


All times are GMT -5. The time now is 03:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration