

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find length of a string without string.h and loop in C?
In this section we will see how to find length of a string without using string header file and loops in C. The string length finding problem can be solved without string.h very easily. We can use recursive function to do it.
But in this example we are not using recursion. We are using another trick to do that. We are using printf() function to get the length. The printf() function returns the number of character it has printed. If we print only that string using a printf() function, we can easily get the length of it.
Example Code
#include<stdio.h> main() { char* my_str = "This is a String"; printf("The string is: "); int length = printf("%s", my_str); printf("\nThe length of string is: %d", length); }
Output
The string is: This is a String The length of string is: 16
- Related Questions & Answers
- Find length of loop in linked list in C++
- C++ Program to Find the Length of a String
- C program to find the length of a string?
- Java string length without using length() method.
- 5 Different methods to find length of a string in C++?
- Program to find length of a list without using built-in length() function in Python
- 5 Different methods to find the length of a string in C++?
- Print 1 to 100 in C++, without loop and recursion
- Find longest length number in a string in C++
- How to find the length of the longest substring from the given string without repeating the characters using C#?
- How to find the length and rank of a jagged array in C#?
- Program to find Length of Bridge using Speed and Length of Train in C++
- Find length of a string in python (3 ways)
- Python Program to Calculate the Length of a String Without Using a Library Function
- Print a pattern without using any loop in C++
Advertisements