Function not returning to main

I have a function which takes input either through STDIN or from input file.It works well for the former case but in the latter case it is not returning to the main function after completing the traversal.Can somebody tell me the error which I have made?

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

void input()
{
		int option;
	    count = 0;
	    cout<<"\n\nEnter the number of page frames : ";
	    cin>>n;
	    cout<<"Enter 0 to input through STDIN or 1 to input from file\n";
	    cin>>option;
	    if(option==0)
	    {
	    	//const int F=n;
	    	cout<<"\n\nEnter the reference string (-1 to finish string) : \n";
	    	cin>>temp;
	    	while(temp != -1)
	    	{

	    		//cout<<"number = "<<temp<<endl;
	    		//cout<<"count="<<count<<endl;
	    		ref[count++]=temp;
	    		cin>>temp;
	    	}

	    	return;


	    }
	    else if(option==1)
	    {
	    	char ch;
	    	int i=0;
	    	char number[2];
	    	int no;
	    	count=0;
	    	fstream inFile;
	    	inFile.open("refstring.txt");
	    	if(!inFile)
	    		cout<<"No such file\n";
	    	else
	    	{
	    		inFile.seekg(0,ios::end);
	    		int length=inFile.tellg();
	    		inFile.seekg(0,ios::beg);
	    		cout<<"Length = "<<length<<endl;

	    		while(!inFile.eof())

	    		{
	    			//cout<<inFile.tellg()<<endl;
	    			inFile.get(ch);
	    			cout<<ch<<endl;
	    			do
	    			{
	    				number[i++]=ch;
	    				inFile.get(ch);

	    			}while(ch!=' ');
	    			//number[i]='\0';
	    			//cout<<number<<endl;
	    			no=atoi(number);
	    			//cout<<"no="<<no;
	    			i=0;
	    			//cout<<"count="<<count;
	    			if(no!=0)
	    			{

	    				ref[count]=no;
	    				cout<<"ref["<<count<<"]="<<no<<endl;
	    				count++;
	    			}
	    			cout<<"Count is "<<count<<endl;



	    		}
	    		




	    	}
	    	inFile.close();
	    	inFile.clear();
                return;





	    }
	    else
	    {
	       	cout<<"Wrong option....Aborting\n";
	       	exit(-1);
	    }




}
I'm not a pro but I think the function isn't returning because it's a void function. In addition, I don't see it trying to return anything because it only says "return; "
The function is void which means it does not return a value.
When you say it's not returning you mean return a value (as the above users assumed) or return control after completing its task meaning has an infinite loop or something?

I check your code and although you define a function there are missing definition for various variables. Is this function member function of a class, do you declare this variables globally or what?
Last edited on
Topic archived. No new replies allowed.