Return to int main()

I am having some trouble with the following code;

 
int main(int argc , char *argv[]) {


When I get an error message inside the above code I am waiting for 5 seconds and I then try to return to the above code with, return 0, etc. Nothing seems to work.

Any help would be greatly appreciated!

Matt.

Last edited on
1
2
3
4
int main( int argc, char *argv[] )
{
        return 0;
}

You're missing the '}' at the end of your main function.
Last edited on
I have tried that...
Googie85 wrote:
I have tried that...

Then, why doesn't it compile? It does on cpp.sh, for me, and most compilers.

If you press the gear icon at the top right of the code above, press edit and run, it will compile.
Last edited on
My code,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main(int argc , char *argv[]) {
HINTERNET connect1 = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);
 
   if(!connect1){
      printf("Connection Failed or Syntax error");
      Sleep(10000);
      InternetCloseHandle(connect1);
 int main();
   }
 
HINTERNET OpenAddress1 = InternetOpenUrl(connect1,"http://127.0.0.1", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_KEEP_CONNECTION, 0);
 
   if ( !OpenAddress1 )
   {
      DWORD ErrorNum = GetLastError();
     printf("Failed to open URL \nError No: ");
        Sleep(10000);
              InternetCloseHandle(connect1);
            InternetCloseHandle(OpenAddress1);
int main();
   }


The above is only a snippit of my source code, it does compile fine, but my program seems to stop after the int main();.

Many Thanks,

Matt.
It looks like you are trying to call main(). Standard C++ does not allow that. Instead you should use a loop, in order to go back to the start when required.
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
int main(int argc , char *argv[]) 
{
    while (true)   // repeat forever
    {    
        HINTERNET connect1 = InternetOpen("MyBrowser",INTERNET_OPEN_TYPE_PRECONFIG,NULL, NULL, 0);

        if (!connect1)
        {
            printf("Connection Failed or Syntax error");
            Sleep(10000);
            InternetCloseHandle(connect1);
            continue;  // go back to start and try again
        }

        HINTERNET OpenAddress1 = InternetOpenUrl(connect1,"http://127.0.0.1", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE|INTERNET_FLAG_KEEP_CONNECTION, 0);

        if ( !OpenAddress1 )
        {
            DWORD ErrorNum = GetLastError();
            printf("Failed to open URL \nError No: ");
            Sleep(10000);
            InternetCloseHandle(connect1);
            InternetCloseHandle(OpenAddress1);
            continue;  // go back to start and try again
        }

        break;  // exit from the loop
    }
    
}


See The continue statement
http://www.cplusplus.com/doc/tutorial/control/

Note: while (true) gives an infinite loop. A break statement is needed in order to exit from the loop.


Edit: I should add, this is just a first idea - it doesn't necessarily seem an ideal solution - there are probably much better approaches.
Last edited on
Thank you so much!!!

Matt.
Topic archived. No new replies allowed.