diff --git a/programs/C/length_string.c b/programs/C/length_string.c new file mode 100644 index 0000000..46af99f --- /dev/null +++ b/programs/C/length_string.c @@ -0,0 +1,23 @@ +#include + +//Created a function to calculate length of string. +int lengthOfString(char stringInput[50]) { + int length = 0, i; + scanf("%[^\n]", stringInput); //Input of the string + + for(i = 0; stringInput[i]!='\0'; i++) + + length++; + + return length; +} + +int main(void) { + char sentence [50]; + int length; + + length = lengthOfString(sentence); // Using the function + printf("%d \n", length); // Printing the length of the sentence + + return 0; +}