We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 80dd25b commit f16e52eCopy full SHA for f16e52e
1 file changed
programs/C/length_string.c
@@ -0,0 +1,23 @@
1
+#include <stdio.h>
2
+
3
+//Created a function to calculate length of string.
4
+int lengthOfString(char stringInput[50]) {
5
+ int length = 0, i;
6
+ scanf("%[^\n]", stringInput); //Input of the string
7
8
+ for(i = 0; stringInput[i]!='\0'; i++)
9
10
+ length++;
11
12
+ return length;
13
+}
14
15
+int main(void) {
16
+ char sentence [50];
17
+ int length;
18
19
+ length = lengthOfString(sentence); // Using the function
20
+ printf("%d \n", length); // Printing the length of the sentence
21
22
+ return 0;
23
0 commit comments