By: Prem Tiwari | Last Updated: | In: C Programming Tutorial
This is a simple program written in C programming language to find the length of a string entered by your while execution of this program.
This program will calculate the length of string without using the strlen()
function. It will count the string length by using the for(i = 0; s[i] != '\0'; ++i);
loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <stdio.h> int main() { char s[1000], i; printf("Enter a string: "); scanf("%s", s); for(i = 0; s[i] != '\0'; ++i); printf("Length of string: %d", i); return 0; } |
Output is:
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari
Tags: c program to find length of string, find length of string in c, find string length in c