Functions
- void va_start(va_list ap, argN);
- void va_copy(va_list dest, va_list src);
- type va_arg(va_list ap, type);
- void va_end(va_list ap)
echo '' ;
The conio.h header file is a C library that provides functions for console input and output in the DOS and Windows environments. “Conio” stands for “console input/output”. This header file is not part of the standard C library and is specific to DOS and Windows systems.
Some commonly used functions declared in conio.h
include:
clrscr()
: Clears the screen.getch()
: Reads a character directly from the console without echoing it.getche()
: Reads a character directly from the console and echoes it.cprintf()
: Prints formatted output to the console.cscanf()
: Reads formatted input from the console.It’s important to note that conio.h
is not standard and is not portable across different platforms or compilers. It was widely used in older DOS-based C programming, but it’s generally not recommended for modern development due to its lack of portability and non-standard nature. Most modern compilers, especially those targeting Unix-like systems, do not support conio.h
. Instead, developers typically use standard input/output functions from stdio.h
for console I/O.
The getch() function in conio.h reads a single character from keyboard. It doesn’t uses any buffer, so entered data is not displayed on the output screen.
The windows.h
header file is a fundamental header file for the Microsoft Windows operating system. It includes declarations for a wide range of functions and data types used in Windows programming. Here’s a basic example demonstrating the usage of windows.h
for creating a simple Windows GUI application:
#include <windows.h> // Function prototype for the window procedure LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int main() { // Get the handle to the instance of this application HINSTANCE hInstance = GetModuleHandle(NULL); // Create the main window HWND hwnd = CreateWindowEx( 0, // Optional window styles L"WindowClass", // Window class L"My First Window", // Window title WS_OVERLAPPEDWINDOW, // Window style // Size and position CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, // Parent window NULL, // Menu hInstance, // Instance handle NULL // Additional application data ); // Display the window ShowWindow(hwnd, SW_SHOWNORMAL); // Enter the message loop MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } // The window procedure LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hwnd, uMsg, wParam, lParam); } return 0; }
This above example creates a simple window using the Windows API. The WindowProc
function is the window procedure, which handles messages for the main window. The CreateWindowEx
function creates the main window, and the ShowWindow
function displays it. The program then enters a message loop (while (GetMessage...)
) where it waits for and processes messages until the user closes the window.
Remember that this is just a basic example, and real-world Windows applications will involve more complexities and considerations. Additionally, GUI programming in Windows often involves using additional libraries, such as MFC (Microsoft Foundation Classes) or newer frameworks like WinUI.
The windows.h
header in Windows programming provides declarations for various functions, data types, and constants used in Windows API. Here are some commonly used predefined functions available in windows.h
:
Function Category | Function | Note |
---|---|---|
Window Management Functions: | CreateWindowEx() | Creates an extended window. |
ShowWindow() | Sets the specified window’s show state. | |
UpdateWindow() | Updates the client area of the specified window. | |
DestroyWindow() | Destroys the specified window. | |
DefWindowProc() | The default window procedure for window messages not processed by your window procedure. | |
Message Handling Functions: | GetMessage() | Retrieves a message from the calling thread’s message queue. |
TranslateMessage() | Translates virtual-key messages into character messages. | |
DispatchMessage() | Dispatches a message to a window procedure. | |
PostQuitMessage() | Posts a quit message to the message queue. | |
Thread Functions: | CreateThread() | Creates a new thread for parallel execution. |
GetCurrentThreadId() | Retrieves the thread identifier of the calling thread. | |
Synchronization Functions: | CreateMutex() | Creates or opens a named or unnamed mutex object. |
CreateEvent() | Creates or opens a named or unnamed event object. | |
WaitForSingleObject() | Waits until the specified object is in the signaled state. | |
ReleaseMutex() | Releases ownership of the specified mutex object. | |
File and File I/O Functions: | CreateFile() | Creates or opens a file or I/O device. |
ReadFile, WriteFile() | Reads from or writes to a file or I/O device. | |
CloseHandle() | Closes an open object handle. | |
Memory Management Functions: | VirtualAlloc() | Reserves or commits a region of memory within the virtual address space of a specified process. |
VirtualFree() | Releases, decommits, or releases and decommits a region of memory. | |
Time Functions: | GetSystemTime() | Retrieves the current system date and time. |
Sleep() | Suspends the execution of the current thread for a specified interval. | |
Miscellaneous Functions: | MessageBox() | Displays a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message. |
GetLastError() | Retrieves the calling thread’s last-error code value. | |
LoadLibrary, GetProcAddress() | Loads a dynamic-link library (DLL) into the calling process’s address space. |
These are just a few examples, and there are many more functions provided by Windows.h for various purposes. When working with Windows programming, documentation is an essential resource to understand and use these functions effectively. The next section only discussed Sleep() function.
if you have the following questions like
Here is your solution,
If you wanna use the delay feature, you can use the Sleep()
function in the Windows platform, based on the compiler the Sleep()
will call in different library files(Some times Sleep function will be winbase.h
, Sometimes different). Don’t worry about that, if you include the windows.h
the header file, that will be taken care of. why because everything all the sleep function necessary headers are already included in windows.h
the file.
#include <windows.h>
Sleep()
function first letter always Uppercase, if you declare in the small case the compiler might generate error “Undefined reference to sleep”. Sleep()
function argument (Milliseconds) should be unsigned long type. If your call [Example : Sleep("ArunEworld")
] Sleep()
function with char type or other types, the compiler will generate an Error.Please note that the sleep
function may not be very precise, and the actual delay could be slightly longer due to system-related factors. If you need more precise timing, you might want to explore other methods or libraries for that purpose.
#include <stdio.h> #include <unistd.h> // for sleep function int main() { printf("ArunEworld: This is before the delay.\n"); // Sleep for 3 seconds sleep(3); printf("ArunEworld: This is after the delay.\n"); return 0; }
In this above example, the program will print the first message, then pause for 3 seconds using sleep(3)
, and finally print the second message after the delay.
Remember to include the <unistd.h>
header for the sleep
function to work.
The below code will be printed ArunEworld website every 1 second
#include <stdio.h> #include <Windows.h> int main() { while(1) { //print the aruneworld website address printf("www.ArunEworld.com.\r\n"); //make a delay every in millisecond Sleep(1000); } return 0; }
#include <stdio.h> #include <Windows.h> int main() { while(1) { //print the aruneworld website address printf("www.ArunEworld.com.\r\n"); //make a delay every in millisecond Sleep("ArunEworld"); } return 0; }
The above code will show the Error like "[Note] expected 'DWORD' but argument is of type 'char *'"
. Why because
the argument should be unsigned long. here ‘Sleep()
ArunEworld'
is a charter pointer.
Refer to the C Examples – Time Delay
stdlib.h in standard C Library header file that provides various functions to perform general utility tasks. It includes functions for memory allocation, process control, random number generation, string conversion, and other fundamental operations.
Key functions include malloc()
for dynamic memory allocation, free()
to release allocated memory, exit()
for program termination, atoi()
for converting strings to integers, and rand()
for generating pseudo-random numbers.
Additionally, <stdlib.h>
declares the NULL
macro for null pointers and defines the EXIT_SUCCESS
and EXIT_FAILURE
constants for program termination status.
Overall, <stdlib.h>
is essential for many C programs, offering foundational functionalities crucial for memory management, program flow control, and data conversion.
functions are in below table, Refer this link for more info
Function | Description |
---|---|
abort() | Stop a Program. |
abs() | Calculate Integer Absolute Value. |
atexit() | Record Program Ending Function. |
atof() | Convert Character String to Float |
atoi() | Convert Character String to Integer |
atol() & atoll() | Convert Character String to Long or Long Long Integer |
bsearch() | Search Array |
calloc() | Reserve and Initialize Storage |
_C_Quickpool_Debug() | Modify Quick Pool Memory Manager Characteristics |
_C_Quickpool_Init() | Initialize Quick Pool Memory Manager. |
_C_Quickpool_Report() | Generate Quick Pool Memory Manager Report |
div() | Calculate Quotient and Reminder |
exit() | End Program |
free() | Release Storage Blocks |
_gcvt1() | Convert Floating Point to String |
getenv() | Search for Enviroment Variable |
_itoa1() | Convert Integer to String |
_ltoa1() | Convert Integer to String |
labs() | Calculate absolute value of long and long long Integer |
llabs() | Calculate absolute value of long and long long Integer |
ldiv() | Perform Long and Long Long Division |
lldiv() | Perform Long and Long Long Division |
malloc() | Reserve Storage Block |
mblen() | Determine Length of Multibyte Character |
mbstowcs() | Convert Multibyte String to a Wide Character String |
mbtowc() | Convert Multibyte Character to a Wide Character |
putenv() | Change/Add Environmental Variable |
qsort() | Sort Array |
rand() | Generate Random Number |
rand_r() | Generate Random Number |
realloc() | Change Reserved Storage Block Size |
srand() | Set Seed fr rand() Function |
strtod() | Convert Character String to Double, Float, and Long Double |
strtod32() | Convert Character String to Decimal Floating-Point |
strtod64() | Convert Character String to Decimal Floating-Point |
strtod128() | Convert Character String to Decimal Floating-Point |
strtof() | Convert Character String to Double, Float, and Long Double |
strtol() | Convert Character String to Long and Long Long Integer |
strtold() | Convert Character String to Double, Float, and Long Double |
strtoll() | Convert Character String to Long and Long Long Integer |
strtoul() | String to unsigned Long Integer |
strtoull() | String to Unsigned Long Long Integer |
system() | Execute a command |
_ultoa1() | Convert Unsigned Long Integer to String. |
wcstombs() | Convert a Wide Character to a Multibyte Character String |
wctomb() | Convert a Wide Character to a Multibyte Character |
The stdio.h header file in C is a standard input-output library that provides functions for input and output operations. It stands for “standard input-output header”. This header file declares several functions, including printf
, scanf
, fopen
, fclose
, fread
, fwrite
, etc., as well as various macros and data types.
std
means Standard and io
means Input-output statementsstdio.h
file contains that statements statementsstdio.h
, functions are scanf()
, printf()
, getchar()
, gets()
, putchar()
, puts()
.Here’s a brief overview of some commonly used functions and macros declared in stdio.h
:
printf
: Used to print formatted output to the standard output (usually the console).scanf
: Used to read formatted input from the standard input (usually the keyboard).fprintf
, fscanf
, sprintf
, sscanf
: Variants of printf
and scanf
for performing formatted I/O operations on files or strings.FILE
: Data type representing a file stream used by functions like fopen
, fclose
, fread
, fwrite
, etc.stdin
, stdout
, stderr
: Predefined file streams representing standard input, standard output, and standard error respectively.Including stdio.h
at the beginning of your C program allows you to use these functions and macros. It’s an essential header file for most C programs, as it provides basic input and output capabilities.
The C Library string.h provides various functions for handling strings in C programming. It includes functions for string manipulation, comparison, copying, concatenation, and searching. Some commonly used functions in string.h include strlen() for determining the length of a string, strcpy() for copying strings, strcat() for concatenating strings, and strcmp() for comparing strings. Additionally, string.h provides functions for searching for substrings within a string, such as strchr() and strstr(). The library also offers functions for converting strings to other data types and vice versa, like atoi() and itoa(). Overall, string.h is a crucial part of the C standard library, providing developers with efficient and convenient tools for working with strings in C programs. Its functions are widely used in various applications, from basic string manipulation to complex text processing tasks.
Read more: C Library – string.h