echo '' ;

Category Archives: C Library

C Library – conio.h

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:

  1. clrscr(): Clears the screen.
  2. getch(): Reads a character directly from the console without echoing it.
  3. getche(): Reads a character directly from the console and echoes it.
  4. cprintf(): Prints formatted output to the console.
  5. 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.

getch()

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.

Read more… →

C Library – windows.h

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:

C Library – windows.h File

#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.

Predefined functions of C Library – windows.h

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:

C Library – windows.h predefined functions List

C Library – windows.h predefined functions

Note

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.

sleep() in C Library – windows.h

if you have the following questions like

  • How to use the delay function in C?
  • How to use the C program delay function in Windows?

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.

  • Rule-1: You should add the header file #include <windows.h>
  • Rule-2: Sleep() function first letter always Uppercase, if you declare in the small case the compiler might generate error “Undefined reference to sleep”.
  • Rule-3: 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.

Sleep() Example-1

Code

#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;
}

Explanation

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.

Sleep() Example-2

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; 
}

Slep() Example-3

#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 Sleep() the argument should be unsigned long. here ‘ArunEworld' is a charter pointer.

Refer to the C Examples – Time Delay


Next

C – Basic
C – Operator
C – Decision making, Branching, Looping
C – Functions
C – Storage Class
C – Extern
C – Array
C – Pointer
C – Memory Allocation
C – Structure
C – Union
C – Structure and Union
C – Macros
C – Preprocessor and Macros
C – File Management
C – Coding Standard
C – Compilers
C – Compiling Process
C File Management
C Library
C Example

C Library – stdlib.h

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.

Read more: C Library – stdlib.h

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 List

functions are in below table, Refer this link for more info

FunctionDescription
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
Read more… →

C Library – stdio.h

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 statements
  • These statements are used to get and put data on computers
  • Ex-1: Can put data to a computer via the keyboard.
  • Ex-2: Can get data and see that in Monitor.
  • Input-output statements are used as a function in c language
  • stdio.h file contains that statements statements
  • So if we use these functions should include stdio.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:

  1. printf: Used to print formatted output to the standard output (usually the console).
  2. scanf: Used to read formatted input from the standard input (usually the keyboard).
  3. fprintf, fscanf, sprintf, sscanf: Variants of printf and scanf for performing formatted I/O operations on files or strings.
  4. FILE: Data type representing a file stream used by functions like fopen, fclose, fread, fwrite, etc.
  5. 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.

Read more… →

C Library – string.h

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

String Understanding

  • String is a collection of characters in between the double quotation “.
  • In C language does not have a data type like string, so we can get this from array of characters.
  • Last character of sting should be null characters ‘/0’.
  • Generally compiler will add the null characters when read a string from computer.
  • Dose not appear null characters ‘/0’ when print the string in computer display.
  • Data length is number of characters in the string with null characters.
  • string handling functions strlen() , strcpy()  , strcat()  , strcmp()  , strrev()  , strupr()   , strlwr()  , strrev()  ,
Read more… →