There was an error while loading. Please reload this page.
1 parent 7690164 commit 3a68ac2Copy full SHA for 3a68ac2
1 file changed
programs/C/length_string.c
@@ -1,26 +1,26 @@
1
#include <stdio.h>
2
-#include <string.h>
3
4
//Created a function to calculate length of string.
5
int LengthOfString(char string[50])
6
{
+ int length = 0, i;
7
+ scanf("%[^\n]" , string); //Input of the string
8
- scanf("%[^\n]" , string); //Input of string with blank spaces
9
- int length = strlen(string);
+ for(i=0; string[i]!='\0'; i++)
10
+ {
11
+ length++;
12
+ }
13
14
return length;
15
}
16
-
17
int main(void)
18
19
char string [50];
20
int length;
21
22
length = LengthOfString(string); // Using the function
23
- printf("Length %d \n" , length); // Printing the length
+ printf("%d \n" , length); // Printing the length
24
25
return 0;
26
-}
+}
0 commit comments