Programming Articles

Page 954 of 2547

C Program for Anagram Substring Search

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 333 Views

In this problem, we are given two strings: one text of size n and another pattern of size m. Our task is to create a program for anagram substring search. Here, we have to find all occurrences of the pattern and all its permutations (anagrams) in the text. An anagram is a word formed by rearranging the letters of another word. Let's take an example to understand the problem − Input text = "xyztrwqyzxfg" pattern = "xyz" Output Found at index 0 Found at index 7 Algorithm ...

Read More

Write a bash script to print a particular line from a file in C

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 411 Views

In C programming, we can read and print a specific line from a file using file handling functions. This involves opening the file, reading through it line by line, and printing the desired line number. Syntax FILE *fopen(const char *filename, const char *mode); char *fgets(char *str, int n, FILE *stream); int fclose(FILE *stream); Method 1: Using Line Counter This approach reads the file line by line and uses a counter to track the current line number − Note: Create a text file named "text.txt" in the same directory with some content before ...

Read More

Write a C program to print 'ABCD' repeatedly without using loop, recursion and any control structure

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 304 Views

In this problem, we have to write a program in C that will print a string 'ABCD' repeatedly without using loop, recursion and any control structure. So, we will have to call or run the same block of code infinite times but without using loop, recursion or control structure which are the most common methods to perform the task. For this, we will run the same program multiple times instead of looping. This will perform our task within the given constraints. The system() method can be employed inside the code that will call the program infinite times. Syntax ...

Read More

Difference between scanf() and gets() in C

Nitin Sharma
Nitin Sharma
Updated on 15-Mar-2026 10K+ Views

In C programming, both scanf() and gets() functions are used to read input from the user. However, they handle input differently and have distinct characteristics that make them suitable for different scenarios. Syntax int scanf(const char *format, ...); char *gets(char *str); Important Note: The gets() function has been removed from the C11 standard due to security vulnerabilities. It is recommended to use fgets() instead. Key Differences Sr. No. Aspect scanf() Function gets() Function 1 Input Reading Reads input according to format specifiers and stops ...

Read More

Writing C/C++ code efficiently in Competitive programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 517 Views

In competitive programming, writing efficient C code is crucial for achieving better performance and rankings. Fast execution and optimal memory usage can make the difference between acceptance and time limit exceeded. Key Concepts Template − Code that works with different data types without rewriting Macro − Named code fragment that gets replaced during preprocessing Dynamic Arrays − Arrays that can resize during runtime Essential Optimization Techniques Fast Input/Output Methods Using scanf() and printf() instead of slower alternatives provides significant performance improvements ? #include int main() { ...

Read More

Writing OS Independent Code in C/C++

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 559 Views

Writing OS-independent code in C allows programs to run across different operating systems without modification. This is achieved using preprocessor macros that detect the target platform at compile time. Syntax #ifdef MACRO_NAME // OS-specific code #elif defined(ANOTHER_MACRO) // Alternative OS code #else // Default code #endif Common OS Detection Macros GCC and other C compilers define platform-specific macros automatically − _WIN32 − Defined for 32-bit and 64-bit Windows _WIN64 − Defined only for 64-bit Windows __unix__ − Defined for Unix-like ...

Read More

mbrtowc() function in C/C++ program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 304 Views

The mbrtowc() function is used to convert a multibyte character sequence to a wide character. This function is part of the C standard library and is defined in the header file. It provides a safe way to convert multibyte characters (like UTF-8) to wide character representation. Syntax size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps); Parameters The function accepts the following parameters − pwc − Pointer to the location where the resulting wide character will be stored s − Pointer to the multibyte character string to be converted n ...

Read More

putwchar() function in C/C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 170 Views

The putwchar() function in C is used to write a wide character to the standard output (stdout). It is the wide character equivalent of the putchar() function and is defined in the header file. Syntax wint_t putwchar(wchar_t wc); Parameters wc − The wide character to be written to stdout Return Value On success: Returns the wide character that was written On failure: Returns WEOF and sets an error indicator Example 1: Writing Single Wide Character This example demonstrates writing a single wide character to stdout ...

Read More

Iseek() in C/C++ to read the alternate nth byte and write it in another file

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 826 Views

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 More

Integer literal in C/C++ (Prefixes and Suffixes)

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 2K+ Views

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 More
Showing 9531–9540 of 25,466 articles
« Prev 1 952 953 954 955 956 2547 Next »
Advertisements