Skip to content

Commit

Permalink
Update length_string.c
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhavkaul authored Oct 25, 2018
1 parent f84e401 commit 7d67f38
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions programs/C/length_string.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#include <stdio.h>

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

for(i=0; string[i]!='\0'; i++)
{
length++;
}
for(i = 0; StringInput[i] != '\0'; i++)

length++;

return length;
}

int main(void)
{
char string [50];
int main(void){
char sentence [50];
int length;

length = LengthOfString(string); // Using the function
printf("%d \n" , length); // Printing the length
length = LengthOfString(sentence); // Using the function
printf("%d \n", length); // Printing the length

return 0;
}

0 comments on commit 7d67f38

Please sign in to comment.