Skip to content

Macro Expansion Proposal #4

@sebetci

Description

@sebetci

Hi @AndrewLaing,

I ran into a problem when I compile and run the Simpletron application in the ex07_28.c file on the Windows 10 operating system. Since I was compiling with GCC using Cygwin, I noticed that the following system command defined in the program was causing the error.

Click to see the relevant source code line in ex11_17v2.c.

    #define PAUSE system( "pause" )
    #define CLEARSCREEN system( "cls" )

I had the same situation when I was running the ex11_17 project; the operating system warned that it could not find the specified system command. To solve this problem on POSIX systems, Windows-based operating systems and Linux distribution operating systems using Cygwin, I have extended the macros you use in the program as follows:

Click to see recommended source code.

#if defined( _POSIX_VERSION )
	#define CLEARSCREEN system( "clear" )
	#define PAUSE       system( "read -n1 -r -p \"Press any key to continue...\" ")
#elif ( defined( __unix__ ) || defined( __linux__ ) )
	#define CLEARSCREEN system( "clear" )
	#define PAUSE       system( "read -n1 -r -p \"Press any key to continue...\" ")
#elif ( defined( _WIN64 ) || defined( _WIN64 ) )
	#define CLEARSCREEN system( "cls" )
	#define PAUSE       system( "pause" )
#endif

I searched for the equivalent of the pause system command in DOS. I found out that there is no pause command directly in the shell. Instead, I learned that the read command is used as follows:

$ read -n1 -r -p "Press any key to continue..."

Thank you for your contributions to the community. I wish you good work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions