Skip to content

Commit f16e52e

Browse files
committed
Create length_string.c
1 parent 80dd25b commit f16e52e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

programs/C/length_string.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)