a function to return the length of a string in c

Solutions on MaxInterview for a function to return the length of a string in c by the best coders in the world

showing results for - "a function to return the length of a string in c"
Felix
11 Jan 2017
1#include <stdio.h>
2#include <string.h>
3int main()
4{
5    char a[20]="Program";
6    char b[20]={'P','r','o','g','r','a','m','\0'};
7
8    // using the %zu format specifier to print size_t
9    printf("Length of string a = %zu \n",strlen(a));
10    printf("Length of string b = %zu \n",strlen(b));
11
12    return 0;
13}
Moritz
02 Nov 2019
1/**
2* A PROGRAM THAT RETURNS THE LENGTH OF A STRING FROM THE USER
3*/
4
5#include <stdio.h>
6
7/**
8* _strlen - takes a string and returns its length
9* @i: counter variable
10* @*s: the string entered by the user from the terminal
11* Return: Length of the string = i
12*/
13int _strlen(char *s)
14{
15        int i;
16
17        for(i = 0; s[i];)
18                i++;
19
20        return(i);
21}
22
23/**
24* main - start of this program
25* @str: string entered by user
26* Return: 0 when runs successfully
27*/
28int main()
29{
30        char str[100];
31
32        printf("Enter your string\n");
33        scanf("%s",str);
34
35        printf("%s is %i characters\n", str, _strlen(str));
36
37        return 0;
38}
queries leading to this page
str len in csecure way to calculate the string length in cc get length of stringlength of a sring in clength of sting in cstring len in cget size of string cc strlenfind length of a string in c no strlenhow to check length of string in cget length of string in cc get len of stringstrlen libraryc code for string lengthc string length functionc string lengthlegnth of string in chow to get the length of a string in cstrlen library in cc how to get the length of an stringstring lenght in cstring lenght clen string cget string length in cget str length c function that returns the length of a string in chow to get string length in cstrlen lib in clen of string cstring length ccount length of string in ccount string length cc programming string lengthlength of str cc 2fal check length on stringstr len cstrlenget length of string ca function to return the length of a string in cwrite a function that returns the length of a string in ccheck len of string clenth of str in cc len of stringhow to find string length in cc program to find the length of a stringcheck size of string in clength function in chow to find the length of string in cc strlen functionspecific check string length in c str length chow to get string length cc programming strlenlength of string clength of string in c with strlensrtlen cfind length of a string in cwhat does strlen do in clength in cfind length of string in cfind len of string in chow to get length of string in cdisplay a string length with strlen in cget string length chow to declare strlen in cstrlen in cc length of stringwrite a c program to find the length of a string length of string in cstr length in cleng of string cstrlen csize of string cinclude strlen cc print string length how to find length of stringin cstring length in cc string get lengthwrite a program in c to find the length of a stringget the length of an string ccalculate length of string in chow to find length of string in cstring lenth in cc string lengthlength of string in cfind the length of string in cstrlen 28 29size of a string clenght of string in clength c stringlength of a string in cc get string lengthstring 27s length in csize of string in cc strlnhow to use strlen in ca function to return the length of a string in c