A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to calculate length of the string without using strlen()
Q:

C program to calculate length of the string without using strlen()

0

C program to calculate length of the string without using strlen()

In this program, we will calculate length of the string without using strlen() functionstrlen() is a library function of string.h that returns length of the string.

Here, we will count the total number of characters available in a string and will not use strlen().

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C example to calculate string length

#include <stdio.h>

/*function to return length of the string*/
int stringLength(char*);

int main()
{
	char str[100]={0};
	int length;

	printf("Enter any string: ");
	scanf("%s",str);
	
	/*call the function*/
	length=stringLength(str);
	
	printf("String length is : %d\n",length);

	return 0;
}

/*function definition...*/
int stringLength(char* txt)
{
	int i=0,count=0;
	
	while(txt[i++]!='\0'){
		count+=1;
	}
	
	return count;
}

Output

Enter any string: IncludeHelp 
String length is : 11

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now