Print Substring of a Given String Without Using Any String Function and Loop in C Last Updated : 15 Jan, 2025 Comments Improve Suggest changes Like Article Like Report In C, a substring is a part of a string. Generally, we use string libary functions or loops to extract the substring from a string and then print it. But in this article, we will learn how to print the substring without using any string function or loops.The simplest method for printing a substring of a string is by using recursion. Let's take a look at an example: C #include <stdio.h> void printSS(char* s, int left, int right) { // Finding the length int n = right - left + 1; // Printing using width specifier for string printf("%.*s", n, s + left); } int main() { char s[] = "Geeks for Geeks"; // Printing the substring "for" printSS(s, 6, 8); return 0; } OutputforExplanation: In this program, printSS() takes starting(left) and ending(right) index of the substring as parameters. It then prints the character at left index in one recursive call and move left index towards right index can call itself again. It does this until left is greater than right index.If the recursive method is also restricted, then we can use the pointer arithmetic with print width specifier inside the printf() function to print the substring.Using Pointer ArithmeticFind the length of the string by calculating the difference between the starting and ending indexes. Then use print width specifier in printf() function print the given length starting from the first character of the string using pointer arithmetic. Let's take a look and an example: C #include <stdio.h> void printSS(char *s, int l, int r) { // Base case if (l > r) { return; } // Print character at s[l] printf("%c", s[l]); // Move pointer to the right and call again printSS(s, l + 1, r); } int main() { char s[] = "Geeks for Geeks"; // Printing the substring "for" printSS(s, 6, 8); return 0; } Outputfor Explanation: In this program, the substring "for" is printed by calling the printSS function with its starting and ending index. The expression s + left moves the pointer to the starting position of the substring, and %.*s ensures that only the specified number of characters (3 in this case) are printed. Comment More infoAdvertise with us Next Article Print Substring of a Given String Without Using Any String Function and Loop in C R Rahul Jain Improve Article Tags : C Language C-String Similar Reads C program to copy string without using strcpy() function In C, the strcpy() function is commonly used for copying strings, but in this article, we will learn how to copy strings without using strcpy() function.The simplest method to copy string without using strcpy() function is by using a loop. Letâs take a look at an example:C#include <stdio.h> vo 2 min read Write a C program to print "GfG" repeatedly without using loop, recursion and any control structure? As we all know the concept of printing the given string repeatedly using various loops(for loop,while loop),recursion and some control structure also. But the question is how we will print the given string repeatedly i.e. infinitely without using any loops,recursion and any control structure? Exampl 1 min read C program to print a string without any quote (single or double) in the program Print a string without using quotes anywhere in the program using C or C++. Note : should not read input from the console. The idea is to use macro processor in C (Refer point 6 of this article). A token passed to macro can be converted to a string literal by using # before it. C // C program to pri 1 min read Write a C program to print "Geeks for Geeks" without using a semicolon First of all we have to understand how printf() function works. Prototype of printf() function is: int printf( const char *format , ...) Parameter format: This is a string that contains a text to be written to stdout.Additional arguments: ... (Three dots are called ellipses) which indicates the vari 2 min read C Program to print numbers from 1 to N without using semicolon? How to print numbers from 1 to N without using any semicolon in C. C #include<stdio.h> #define N 100 // Add your code here to print numbers from 1 // to N without using any semicolon What code to add in above snippet such that it doesn't contain semicolon and prints numbers from 1 to N?We stro 2 min read Convert a floating point number to string in C Write a C function ftoa() that converts a given floating-point number or a double to a string. Use of standard library functions for direct conversion is not allowed. The following is prototype of ftoa(). The article provides insight of conversion of C double to string. ftoa(n, res, afterpoint) n -- 3 min read C program to print characters without using format specifiers As we know that there are various format specifiers in C like %d, %f, %c etc, to help us print characters or other data types. We normally use these specifiers along with the printf() function to print any variables. But there is also a way to print characters specifically without the use of %c form 1 min read Write one line functions for strcat() and strcmp() Recursion can be used to do both tasks in one line. Below are one line implementations for stracat() and strcmp(). C /* my_strcat(dest, src) copies data of src to dest. To do so, it first reaches end of the string dest using recursive calls my_strcat(++dest, src). Once end of dest is reached, data i 2 min read Print a long int in C using putchar() only Write a C function print(n) that takes a long int number n as argument, and prints it on console. The only allowed library function is putchar(), no other function like itoa() or printf() is allowed. Use of loops is also not allowed. We strongly recommend to minimize the browser and try this yoursel 2 min read isalpha() and isdigit() functions in C with cstring examples. isalpha(c) is a function in C which can be used to check if the passed character is an alphabet or not. It returns a non-zero value if it's an alphabet else it returns 0. For example, it returns non-zero values for 'a' to 'z' and 'A' to 'Z' and zeroes for other characters.Similarly, isdigit(c) is a 2 min read Like