Created
January 18, 2024 16:04
-
-
Save siddharthaborah/0b8ffe4ef922427aaf639f8b393410a8 to your computer and use it in GitHub Desktop.
write a program to find the number of white spaces from a string without using library function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int countchar(char str[]); | |
int main(){ | |
int i, lenOfStr, countWhiteSpace; | |
char str[50]; | |
printf("Enter the string: "); | |
gets(str); | |
lenOfStr = countchar(str); | |
printf("length of character: %d",lenOfStr); | |
countWhiteSpace = 0; | |
for(i=0; i<lenOfStr; i++){ | |
if (str[i] != ' ') | |
continue; | |
else | |
countWhiteSpace = countWhiteSpace + 1; | |
} | |
printf("\nWhitespace in the string: %d",countWhiteSpace); | |
return 0; | |
} | |
int countchar(char str[]){ | |
int count=0, i; | |
for(i=0; str[i]!='\0'; i++){ | |
count++; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very cute