hi there)

guys, plesae tell me - what should i change in this code to see message in a console window (i also need define the OS) =

#include <stdio.h> 
#if defined(_WIN32) || defined (_WIN64) 
   #include <windows.h> 
   #define WINDOWSS 1;
#endif
 
int main()
 {
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	 int mainmenu();
   mainmenu();
  printf("\n%s",mtext );


 }
   #if defined WINDOWSS
int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss) 
{
  int mainmenu();
	 mainmenu();
char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
  printf("\n%s",mtext );

 return TRUE;
 }
#endif
 
int mainmenu()
  {
     char ch; 
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	 char* errmes = " Error(!) = Main menu does not support this command.\n Make sure that your task number is from menu set of commands and try again. " ;
	 printf("\n%s",mtext );
	 ch = getchar();
	 switch(ch)
     {
		case '0': exit(0);  
		case '1': exit(0); break;
		default: printf("\n%s\n", errmes);
	 }
 return 1; 	 
  }

Remove this line

int mainmenu();

from both 'main' and 'winmain'.
and add a prototype of the function mainmenu at the beginning .

...
int mainmenu(void);

int main()
...
commented: ++ +3

diwakar wagle , thank you ) removed line , but console isn't showed =

#include <stdio.h> 
#include <stdlib.h>
#if defined(_WIN32) || defined (_WIN64)    #include <windows.h> 
   #define WINDOWSS 1;
#endif

int mainmenu(void);
int main()
 {
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	  mainmenu();
	  printf("\n%s",mtext );
  
  printf("\n%s",mtext );


 }
   #if defined WINDOWSS
int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss) 
{
 
	 mainmenu();
char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
  printf("\n%s",mtext );

 return TRUE;
 }
#endif
 
int mainmenu(void)
  {
     char ch; 
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	 char* errmes = " Error(!) = Main menu does not support this command.\n Make sure that your task number is from menu set of commands and try again. " ;
	 printf("\n%s",mtext );
	 ch = getchar();
	 switch(ch)
     {
		case '0': exit(0);  
		case '1': exit(0); break;
		default: printf("\n%s\n", errmes);
	 }
 return 1; 
  }

your program worked correctly for me using vc++ 2010 express. Below is the output I got on the console window. But you need to clear the input keyboard buffer after getchar() to remove the Enter key '\n'.

Please specify the number of the task.
 * You can choose on number from set = {1}
 * Specify "0" to exit
3

 Error(!) = Main menu does not support this command.
 Make sure that your task number is from menu set of commands and try again.

 Please specify the number of the task.
 * You can choose on number from set = {1}
 * Specify "0" to exit

 Please specify the number of the task.
 * You can choose on number from set = {1}
 * Specify "0" to exit
Press any key to continue . . .
commented: ++++ +3

hm....I use Pelles C and nothing happen there , even after building .exe file

I've build it as "win32 program" 0 may the problem in the type of project?

what type of project should I choose to have access to both of console and window interface ? is it upon the whole possible in Pelles C compiler ? does anybody know? tell please

you need to build a console project. Most likely your problem is that the program runs correctly but quickly removes the console window when its done and you can not see what happened. Programmers commonly put something at the end of the program to make it stop so that you can see it. Add getchar(); just after line 14 in main()

you need to build a console project

if i write =

#include <windows.h>

in console compiler shows more than 100 errors with system types))
it doesn't work even after

int mainmenu(void);
int main()
 {
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	  mainmenu();
	  printf("\n%s",mtext );
      
  printf("\n%s",mtext );
getchar();
getchar();

 }

Post the first two or three error messages.

errors and warnings =

error #2001: Syntax error: expected ';' but found 'INT64'.
C:\Program Files\PellesC\Include\Win\basetsd.h(17): warning #2099: Missing type specifier; assuming 'int'.
C:\Program Files\PellesC\Include\Win\basetsd.h(21): error #2121: Redeclaration of '__int64'.
C:\Program Files\PellesC\Include\Win\basetsd.h(21): error #2001: Syntax error: expected ';' but found 'UINT64'.
C:\Program Files\PellesC\Include\Win\basetsd.h(21): warning #2099: Missing type specifier; assuming 'int'.
C:\Program Files\PellesC\Include\Win\basetsd.h(156): error #2121: Redeclaration of '__int64'.

...............
......
.........
C:\Program Files\PellesC\Include\Win\winnt.h(4657): error #2047: Expected a field name.
C:\Program Files\PellesC\Include\Win\winnt.h(4660): error #2047: Expected a field name.
C:\Program Files\PellesC\Include\Win\winnt.h(4664): error #2186: 'unsigned long int' is an illegal bit-field type.
C:\Program Files\PellesC\Include\Win\winnt.h(4665): error #2186: 'unsigned long int' is an illegal bit-field type.

If you want to run the above program, you should compile it as a console program. But when I compiled and ran your program,the winmain part didn't show up. I had to comment out the 'main' part to do so.

#include <stdio.h>
#if defined(_WIN32) || defined (_WIN64)
   #include <windows.h>
   #define WINDOWSS 1;
#endif
int mainmenu(void);
/*int main()
 {
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;

   mainmenu();
  printf("\n%s",mtext );
  getchar();


 }*/
#if defined WINDOWSS

int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss)
{

	 mainmenu();
char* mtext = " running WinMain version. \n" ;
  printf("\n%s",mtext );

 return TRUE;
 }
#endif

int mainmenu(void)
  {
     char ch;
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	 char* errmes = " Error(!) = Main menu does not support this command.\n Make sure that your task number is from menu set of commands and try again. " ;
	 printf("\n%s",mtext );
	 ch = getchar();
	 switch(ch)
     {
		case '0': exit(0);
		case '1': exit(0); break;
		default: printf("\n%s\n", errmes);
	 }
 return 1;
  }
output

 Please specify the number of the task.
 * You can choose on number from set = {1}
 * Specify "0" to exit


 Error(!) = Main menu does not support this command.
 Make sure that your task number is from menu set of commands and try again.

 running from WinMain.

what type of project should I choose to have access to both of console and window interface ?

If you want to compile it as a 'Win32' program then you can use the console functions provided with the 'winapi'.

I installed your compiler and discovered the problem you are having. If you want to include windows.h in a console project you have to enable Microsoft Extensions. To to that select menu Project --> Project Options (at the bottom of the list) --> click the Compiler tab, then in the check boxes on the right select Enable Microsoft Extensions.

After doing that the program compiles and runs just as I posted previously without making any other changes to your source code.

the compiler (Pelles C) show (after more than 100 errors) message (if build as console program) =

If you are compiling a Windows program, make sure you use the /Ze option!

what does it mean?

That means he is using a different compiler than you are. Just ignore it. Pelles C has no such option.

the compiler (Pelles C) show (after more than 100 errors) message (if build as console program) =

what does it mean?

ok. i'll try

make the change I told you about and your problem will be resolved.

Ancient Dragon , big thanks! )) but do you know - why standart 32bit project doesn't want to show console window - my be in this case it'll heip if also add some options?

It does show the console window. It executes main(), not WinMain().

but the winmain() is the entry point for windows program.....
why compiler doesn't compiler such code =

#if defined WINDOWSS
int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss) 
{
 
	 mainmenu();
char* mtext = " WINDOWSS\n" ;
  printf("\n%s",mtext );
getchar(); getchar();
 return TRUE;
 }
#else
int main()
 {
	 char* mtext = " LINUXX \n" ;
	  mainmenu();
	  printf("\n%s",mtext );
     printf("\n%s",mtext );
getchar();
	getchar();

 }
#endif

error =

POLINK: error: Unresolved external symbol '_main'.
POLINK: fatal error: 1 unresolved external(s).

It does show the console window. It executes main(), not WinMain().

if build as win32 console program (exe) - yes ,
but if build as win32 program (exe) - no

That means he is using a different compiler than you are. Just ignore it.Pelles C has no such option.

Yes, it does.
Actually if "Enable Microsoft Extensions" option is unchecked, then compiler will issue the message:

If you are compiling a Windows program, make sure you use the /Ze option!

So '-Ze' is a command line option for the compiler which means 'Enable Microsoft Extensions'. Anyways, I'm glad that the issue has been resolved.

but the winmain() is the entry point for windows program.....
why compiler doesn't compiler such code =

This example code may help you, it compiles as a 'win32' EXE.

#include <windows.h>

void NewLine(void);
void ScrollScreenBuffer(HANDLE, INT);

HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss){
    LPSTR msg="This is a win32 console";
    DWORD cWritten,cRead;
    char chBuffer[256];
    
    //Create console
    if(AllocConsole()==0){
        MessageBox(NULL, TEXT("AllocConsole"), TEXT("Console Error"),
                   MB_OK);
        return 1;
    }
    
    // Get handles to STDIN and STDOUT.
    hStdin = GetStdHandle(STD_INPUT_HANDLE);
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hStdin == INVALID_HANDLE_VALUE ||hStdout == INVALID_HANDLE_VALUE){
        MessageBox(NULL, TEXT("GetStdHandle"), TEXT("Console Error"),
                   MB_OK);
        return 1;
    }

    // Write to STDOUT and read from STDIN by using the default
    while (1){
        if (! WriteFile(
            hStdout,               // output handle
            msg,                   // prompt string
            lstrlenA(msg),         // string length
            &cWritten,             // bytes written
            NULL) )                // not overlapped
        {
            MessageBox(NULL, TEXT("WriteFile"), TEXT("Console Error"),
                MB_OK);
            return 1;
        }

        if (! ReadFile(
            hStdin,    // input handle
            chBuffer,  // buffer to read into
            255,       // size of buffer
            &cRead,    // actual bytes read
            NULL) )    // not overlapped
        break;
        if (chBuffer[0] == 'q') break;//press 'q' to quit
    }

   return 0;
  }
commented: ++++++ +3

diwakar wagle thanks - I've understande understood you idea of using external winapi faciities to get the console window , but I more need to write code which can be compiled under linux OS - so i need main() func - because it's standart entry point for unox (as i know)))

I don't understand - why compiler allows such code =

#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32) || defined (_WIN64) 
	#include <windows.h>
	#define WINDOWSS 1
#endif



 #if defined WINDOWSS
	int main()
	 {
		 char* mtext = "  it's WinMain() code \n" ;
		  printf("\n%s",mtext );
		 return TRUE;
	 }
#else
	int main()
	 {
		 char* mtext = " it's main() code \n" ;
		  printf("\n%s",mtext );
	        return TRUE;
	}
#endif

but doesn't allow such =

#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32) || defined (_WIN64) 
	#include <windows.h>
	#define WINDOWSS 1
#endif



 #if defined WINDOWSS
	int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss)
	 {
		 char* mtext = "  it's WinMain() code \n" ;
		  printf("\n%s",mtext );
		 return TRUE;
	 }
#else
	int main()
	 {
		 char* mtext = " it's main() code \n" ;
		  printf("\n%s",mtext );
	        return TRUE;
	}
#endif

I don't understand - why compiler allows such code =

You can do like this then.

#if defined(_WIN32)||defined(_WIN64)

//Windows specific includes and code goes here..

#elif defined(linux)

//linux specific includes and code goes here..

#endif

my previous example is the same as yours one...... - but problem isn't in this point - the problem is in fact that the compiler demands main() func for win23 console program when it should use WinMain() func. instead of main()

Yes, it does.
Actually if "Enable Microsoft Extensions" option is unchecked, then compiler will issue the message:

If you are compiling a Windows program, make sure you use the /Ze option!

So '-Ze' is a command line option for the compiler which means 'Enable Microsoft Extensions'. Anyways, I'm glad that the issue has been resolved.

I stand corrected, my apologies for the misinformation.

my previous example is the same as yours one...... - but problem isn't in this point - the problem is in fact that the compiler demands main() func for win23 console program when it should use WinMain() func. instead of main()

There is probably some other changes you have to make for win32 projects. I just created a win32 application project and it compiled and ran without error. You should do the same and check the project settings to see what other changes you might have to make in your program.

as i learned from here the standart entry point for windows console program is main() function - not WinMain() - it makes the situation more clear and it means that i don't understand the c att all ))) .
big thanks you Ancient Dragon and you diwakar wagle ))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.