473,396 Members | 1,816 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.

Main loop

Hi all,

I was wondering what's the way to create your own main loop? Say I want
to index file and the indexing should be happening in the main loop and
when there are no files to index, the process will just run as a
daemon. I know this is possible with a simple while(1) but what a about
a true main loop?

Regards

Jan 26 '06 #1
2 10657
gamehack wrote:
Hi all,

I was wondering what's the way to create your own main loop? Say I
want to index file and the indexing should be happening in the main
loop and when there are no files to index, the process will just run
as a daemon. I know this is possible with a simple while(1) but what a
about a true main loop?

Regards


I don't really understand what you mean by the "true main loop",
especially if it's not:

int main(void)
{
while (1)
{
/* do whatever */;
}
}

This is a perfectly acceptable and understandable way of running stuff
"forever" in a C program. Could you clarify, please?

Cheers

Vladimir

PS
There are also perfectly non-standard and non-portable ways of having
some function other than main() running as your "C" application, but I
don't think that's what you meant.

--
Q: How many Martians does it take to screw in a lightbulb?
A: One and a half.

Jan 26 '06 #2
gamehack wrote:

Hi all,

I was wondering what's the way to create your own main loop? Say I want
to index file and the indexing should be happening in the main loop and
when there are no files to index, the process will just run as a
daemon. I know this is possible with a simple while(1) but what a about
a true main loop?


What's not "true main" about:

int main(int argc,char *argv[])
{
while (1)
{
... everything here ...
}
return(0);
}

If you don't like that for some reason:

int main(int argc,char *argv[])
{
while (1)
{
main2(argc,argv);
}
return(0);
}

int main2(int argc,char *argv[])
{
... put everything that was "main()" here ...
}

What, exactly, are you trying to do?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Jan 26 '06 #3

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

Similar topics

4
by: Rhamphoryncus | last post by:
First a bit about myself. I've been programming in python several years now, and I've got several more years before that with C. I've got a lot of interest in the more theoretical stuff (language...
5
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If...
8
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program...
2
by: Tim | last post by:
The are 2 threads - main thread and worker thread. The main thread creates the worker thread and then the worker thread runs in an infinite while loop till it is asked to exit by setting an event....
6
by: gamehack | last post by:
Hello all, I've thought about having to implement 2 functions, say enter_main_loop(func_name); and a function called quit_application(); which terminates the program. The enter_main_loop() can...
37
by: Army1987 | last post by:
Is that in the object line a conforming program? If so, why? If not, why? I'd expect it to be much like int main(void) { for (;;); } But if I compile it with lcc-win32 and run it in its...
15
by: arnuld | last post by:
i am not able to figure out the error: /* C++ Primer - 4/e * * exercise 7.16 * STATEMENT: * write a programme that accepts the arguments to main. print * the values passed to main. *...
2
by: ats | last post by:
I have a project I am starting with Sub Main. In my Sub Main I currently have one line of code which is frmMenu.Initialise This event runs through some code that eventually shows the form....
2
by: lilyumestar | last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours Error Message ...
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.