Write a function mysubstr() in C that doesn’t use any string function, doesn’t use any loop and prints substring of a string. The function should not modify contents of string and should not use a temporary char array or string.
For example mysubstr(“geeksforgeeks”, 1, 3) should print “eek” i.e., the substring between indexes 1 and 3.
One solution is to use recursion. Thanks to Gopi and oggy for suggesting this solution.
How to do it if recursions is also not allowed?
We can always use pointer arithmetic to change the beginning part. For example (str + i) gives us address of i’th character. To limit the ending, we can use width specifier in printf which can be passed as an argument when * is used in format string.
This article is contributed by Rahul Jain. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Write a C program to print "GfG" repeatedly without using loop, recursion and any control structure?
- How to print a number 100 times without using loop and recursion in C?
- Print a number 100 times without using loop, recursion and macro expansion in C?
- How will you print numbers from 1 to 100 without using loop?
- How will you print numbers from 1 to 100 without using loop? | Set-2
- Print 1 to 100 in C++, without loop and recursion
- How to find length of a string without string.h and loop in C?
- How to print range of basic data types without any library function and constant in C?
- Print "Hello World" in C/C++ without using any header file
- How to concatenate two integer arrays without using loop in C ?
- C program to print a string without any quote (singe or double) in the program
- To find sum of two numbers without using any operator
- Print all possible combinations of the string by replacing '$' with any other digit from the string
- Implementing ternary operator without any conditional statement
- Write a C program to print "Geeks for Geeks" without using a semicolon
- Print "Even" or "Odd" without using conditional statement
- Print individual digits as words without using if or switch
- C Program to print numbers from 1 to N without using semicolon?
- How to print a semicolon(;) without using semicolon in C/C++?
- C program to print characters without using format specifiers