Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Function strlen in C programming

September 19, 2013 Posted by: GPA Views: 26849 0 comments

Problem

Write simple program using strlen() function in C programming.  

Solution

In this article, You will know how to get length of the input string using strlen() function of header file <string.h>.

Declaration:

size_t strlen(const char *str);

This function takes a string as an argument and returns the lenght of input string.

Example:



#include <stdio.h>
#include <stdlib.h>
#include <string.h>//include this header file for function lenght
//main function
int main(int argc, char *argv[])
{
char str[50];//variable for input String
printf("globalproganswer.com\n");
printf("Enter string: ");//promt user to enter string
gets(str);//read string from keyboard
//show result
printf("The length of input string is: %lu",strlen(str));
printf("\n");//new line
system("PAUSE"); //delay
return 0;
}

Output

Function strlen

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe