From f16e52e6310252a68f607051b113d78ca61bf4a5 Mon Sep 17 00:00:00 2001 From: Sambhav Date: Thu, 25 Oct 2018 15:19:12 +0530 Subject: [PATCH] Create length_string.c --- programs/C/length_string.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 programs/C/length_string.c 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; +}