Answers for "c program to find string length"

C
4

string length c

#include <stdio.h>
#include <string.h>
int main()
{
    char a[20]="Program";
    char b[20]={'P','r','o','g','r','a','m','\0'};

    // using the %zu format specifier to print size_t
    printf("Length of string a = %zu \n",strlen(a));
    printf("Length of string b = %zu \n",strlen(b));

    return 0;
}
Posted by: Guest on October-01-2020
2

length of a char array in c

char chararray[10];
size_t len = strlen(chararray);
Posted by: Guest on May-24-2020
1

a function to return the length of a string in c

/**
* A PROGRAM THAT RETURNS THE LENGTH OF A STRING FROM THE USER
*/

#include <stdio.h>

/**
* _strlen - takes a string and returns its length
* @i: counter variable
* @*s: the string entered by the user from the terminal
* Return: Length of the string = i
*/
int _strlen(char *s)
{
        int i;

        for(i = 0; s[i];)
                i++;

        return(i);
}

/**
* main - start of this program
* @str: string entered by user
* Return: 0 when runs successfully
*/
int main()
{
        char str[100];

        printf("Enter your string\n");
        scanf("%s",str);

        printf("%s is %i characters\n", str, _strlen(str));

        return 0;
}
Posted by: Guest on August-04-2021

Code answers related to "c program to find string length"

Code answers related to "C"

Browse Popular Code Answers by Language