In: Computer Science
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
Source Code:
Output:
Code in text format (See above images of code for indentation):
/*include library files*/
#include <stdio.h>
/*main function*/
int main()
{
int characters(char[]);
/*variables*/
char str[50];
int n;
/*read a string from user*/
printf("Enter a string: ");
scanf("%s",str);
/*function call*/
n=characters(str);
/*print total characters*/
printf("Total number of characters is: %d",n);
return 0;
}
/*function definition*/
int characters(char str[])
{
/*variables*/
int i,c=0;
/*using loop count characters*/
for(i=0;str[i]!='\0';i++)
c++;
/*return count*/
return c;
}