20_10

Write a C program to find number of blank space in a sentence(Do not use the strlen() function).

Source code:

 //Write a C program to find number of blank space in a sentence

#include <stdio.h>

int main()

{

    char s[1000], ch;

    int i = 0, count=0; /*i is array index and count is to count blank */

printf("Enter your sentence:");

    while(ch != '\n')    /* terminates if user hit enter */

    {

        ch = getchar();

        s[i] = ch;

        i++;

    }

    s[i-1] = '\0';       /* inserting null character at end */

for(i = 0; s[i] != '\0'; ++i)

    {

    if (s[i] == ' ')

    count += 1; 

    }   

    

printf("No. of blank space = %d", count);

return 0;

}

Output:

C program to find number of blank space in a sentence


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...