Skip to content

Instantly share code, notes, and snippets.

@siddharthaborah
Created January 18, 2024 16:04
Show Gist options
  • Save siddharthaborah/0b8ffe4ef922427aaf639f8b393410a8 to your computer and use it in GitHub Desktop.
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
#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;
}
@akhatabhowmik
Copy link

very cute

@siddharthaborah
Copy link
Author

findWhiltespaceInAStringOutput

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment