Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 936 of 2109
Iseek() in C/C++ to read the alternate nth byte and write it in another file
The lseek() function in C is used to change the file offset (position) of the file descriptor. It allows us to read data from specific positions in a file by moving the file pointer. In this tutorial, we'll demonstrate how to read alternate nth bytes from one file and write them to another file. Note: This program requires file I/O operations with system calls that may not work in all online compilers. Create "start.txt" with sample content before running. Syntax off_t lseek(int fd, off_t offset, int whence); Parameters fd − ...
Read MoreInteger literal in C/C++ (Prefixes and Suffixes)
Integer literals in C are numeric values written directly in the source code to represent integer constants. They can be modified using prefixes to specify the base (decimal, octal, hexadecimal, binary) and suffixes to specify the data type (int, long, unsigned, etc.). Integer literals are of two types − Prefixes − Indicate the number base. For example, 0x10 represents hexadecimal value 16. Suffixes − Specify the data type. For example, 123LL represents a long long integer. Syntax // Prefixes decimal_literal (no prefix) 0octal_literal (prefix ...
Read MoreINT_MAX and INT_MIN in C/C++ and Applications
In C programming, INT_MAX and INT_MIN are predefined macros that represent the maximum and minimum values that can be stored in an int variable. These macros are defined in the header file and are essential for boundary checking and initialization in various algorithms. Syntax INT_MAX /* Maximum value for int */ INT_MIN /* Minimum value for int */ Basic Example Let's see how to use INT_MAX and INT_MIN in a simple program − #include #include int main() { ...
Read MoreFind the Longest Substring Containing Vowels in Even Counts in C++
The problem of finding the longest substring with vowels appearing an even number of times can be solved efficiently using bit manipulation and prefix sums. We need to track the parity (odd/even count) of each vowel ('a', 'e', 'i', 'o', 'u') as we traverse the string. Syntax int findLongestSubstring(char* s); Algorithm Steps The approach uses a bitmask to represent the parity state of vowels − Use a 5-bit mask where each bit represents parity of vowels a, e, i, o, u Store the first occurrence of each mask state When a mask ...
Read MoreCreating a C/C++ Code Formatting tool with help of Clang tools
In this tutorial, we will be discussing how to create a C/C++ code formatting tool using Python and clang-format. This tool automatically formats all C/C++ source files in a project directory according to specified coding standards. Installation Requirements: sudo apt install python3 sudo apt install clang-format How It Works The tool works by recursively scanning directories for C/C++ files and applying clang-format to each file. It uses Python's os.walk() to traverse directories and identifies source files by their extensions. Example: Python Code Formatter Script Create a Python file named format_code.py in your project ...
Read MoreCreate Directory or Folder with C/C++ Program
Creating a folder or directory on your computer is an important task in programming. A directory is like a container that helps store and organize files. In C, you often need to create directories to store data, logs, or configuration files. Creating directories makes file management easier. For example, if your program needs to store logs, it should check if a "logs" folder exists. If not, it can create the folder automatically, so you don't have to do it manually. In this article, we'll show you how to create a directory in C using the mkdir() function. ...
Read MoreCore Dump (Segmentation fault) in C/C++
Core dump (segmentation fault) is a runtime error that occurs when a program tries to access memory that it isn't allowed to access or tries to access memory in a way that isn't allowed. This results in the operating system terminating the program abnormally to prevent potential system damage. A segmentation fault typically happens when code tries to write to read-only memory, accesses corrupt memory locations, or violates memory access permissions. Syntax /* Common scenarios that cause segmentation faults */ char *ptr = NULL; *ptr = 'A'; ...
Read MoreConverting Strings to Numbers in C/C++
In C programming, converting strings to numbers is a common task that can be accomplished using several standard library functions. C provides multiple approaches to convert string representations of numbers into their corresponding numeric values. Syntax int atoi(const char *str); long atol(const char *str); double atof(const char *str); long strtol(const char *str, char **endptr, int base); double strtod(const char *str, char **endptr); Method 1: Using atoi() for Integer Conversion The atoi() function converts a string to an integer value − #include #include int main() { ...
Read MoreConvert a String to Integer Array in C/C++
In C, converting a comma-separated string to an integer array involves parsing the string character by character and extracting numeric values. This process requires traversing the string, identifying delimiters (commas), and converting individual number substrings to integers. Syntax // Function to convert string to integer array void convertStringToArray(char str[], int arr[], int *size); Example: Using Character-by-Character Parsing This approach traverses the string and builds integers by accumulating digits until a comma is encountered − #include #include void convertStringToArray(char str[], int arr[], int *size) { int i = 0, j = 0, num = 0; int len = strlen(str); for (i = 0; i = '0' && str[i]
Read MoreHow to add "graphics.h" C/C++ library to gcc compiler in Linux
In C programming, the graphics.h library provides functions for creating graphics programs. However, this library is not part of the standard C library and requires special installation on Linux systems. Here we'll show how to install and use the graphics library with gcc compiler. Installation Requirements Before using graphics.h, you need to install the required packages and compile the libgraph library on your Linux system. First, install the build essentials and required dependencies − sudo apt-get install build-essential sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev ...
Read More