Skip to content

Commit

Permalink
Update length_string using loop
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhavkaul committed Oct 23, 2018
1 parent 7690164 commit 3a68ac2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions programs/C/length_string.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include <stdio.h>
#include <string.h>

//Created a function to calculate length of string.
int LengthOfString(char string[50])
{
int length = 0, i;
scanf("%[^\n]" , string); //Input of the string

scanf("%[^\n]" , string); //Input of string with blank spaces
int length = strlen(string);
for(i=0; string[i]!='\0'; i++)
{
length++;
}

return length;
}


int main(void)

{
char string [50];
int length;

length = LengthOfString(string); // Using the function

printf("Length %d \n" , length); // Printing the length
printf("%d \n" , length); // Printing the length

return 0;
}
}

0 comments on commit 3a68ac2

Please sign in to comment.