Print Substring of a Given String Without Using Any String Function and Loop in C Last Updated : 15 Jan, 2025 Summarize Comments Improve Suggest changes Share 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 C program to copy string without using strcpy() function K kartik 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 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 Like