Main Resursive is it possible


 
Thread Tools Search this Thread
Top Forums Programming Main Resursive is it possible
# 1  
Old 04-05-2007
Data Problem With Main Resursive

Friends I am Trying this code to call main Recursively But It is showing segmentation errot

#include<stdio.h>
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==5)
{
exit(0);
}
else
{
main();
}
}
}
# 2  
Old 04-05-2007
Data How Many Times The Code will Run

Dear All,
I have a code in C language i.e.
#include<stdio.h>
main()
{
float i;
for(i=0.0;i<10.0;i=i+0.1)
{
printf("%f",i);
}
}

Can any body tell me how many times this code will run?????????
# 3  
Old 04-05-2007
The loop will execute 100 times.
# 4  
Old 04-05-2007
Have you tried it yourself ?

Smilie

Is there any specific question about the for loop and number of times of execution
# 5  
Old 04-09-2007
Data Main Resursive is it possible

Dear Friends,
I just want to know that is it possible to call main function through main means main recursive. I am trying to do so but not getting the proper solution.
So if it is possible then please send me the proper code.
Smilie Smilie
# 6  
Old 04-09-2007
Main recursive is possible. Can you post your code? No one can tell you why it isn't working if they can't take a look at it.
# 7  
Old 04-09-2007
Main Resursive

Hi
i think it's possible but its in differnt way.
i am sendin u code just chk it.
Code:
int main()
{
static int i = 0;
if(++i == 5)
{
printf("Exiting...\n");
exit(0);
}
else
{
printf("Calling main()...\n");
main();
}
return 0;
}

Smilie


Hi dear I checked u r program...
if u will make the int to static then it work and u need to remove the for loop
i think there is no need to call for loop in recursion. just the exmple given by me

Last edited by manoj.rana; 04-09-2007 at 10:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ISSUE IN main script

Hi , I have a script that will move files which have a datetime >= currentdate-N from a source to destination folder.the input parameter are 1) Configurable N days value,2) source folderand 3) destination folder and finally the output would be The old files are moved...I have developed the... (14 Replies)
Discussion started by: nks342
14 Replies

2. Shell Programming and Scripting

$? and main return value

It seems $? can only contain one byte. see below: int main() { return 0x12345678; } After I run the code and check the $? value it output 120, obviously it is the decimal of the last byte of 0x12345678. And if I return a value less than 255, the $? value seems right. Why? and... (3 Replies)
Discussion started by: vistastar
3 Replies

3. UNIX and Linux Applications

Sendmail: help with main.mc

We compile the sendmail.cf file using main.mc. I have managed to place all of our configuration options in main.mc without a problem, with the exception of one. I want to have the HelpFile commented out by default in sendmail.cf. How can I instruct main.mc to place an entry for HelpFile in... (1 Reply)
Discussion started by: dangral
1 Replies

4. Programming

main function

Is it possible to execute any function before main() function in C or C++. (6 Replies)
Discussion started by: arun.viswanath
6 Replies

5. UNIX for Dummies Questions & Answers

main makefile

hello everyone.. am having problem with my so-called main makefile all my files are in the same folder, i was planning to make a single makefile that would make two executable but I got some errors so I separated them and used now i was wondering if I could create a single makefile... (6 Replies)
Discussion started by: ideur
6 Replies

6. HP-UX

How to go to main prompt

Hi: I am new to HP-UX. After the system starts up, it is written in the documents that press any key within 10 sec to interrupt, and go to the main prompt, where I can select the boot device or boot from CD to recover system. However if I interrupt boot, it goes straight to HPUX> prompt. Please... (2 Replies)
Discussion started by: amitra123
2 Replies
Login or Register to Ask a Question