Computer Science, asked by thaufiq1, 1 year ago

write a program to accept a string and count the number of spaces between them

Answers

Answered by Gautam25arora
2

/* Count letters, digits, whitespaces and other chars in a given string */

#include <stdio.h>

void main()

{

char str [81];

int nletter, ndigit, nspace, nother; /* char counts */

int i;

clrscr();

printf("Enter a line of text:\n");

gets(str);

/* count characters in string str */

nletter = ndigit = nspace = nother = 0; /* init counts */

i = 0;

while (str[i] != '\0')

{

char ch= str[i];

if (ch>= 'A' && ch<= 'Z' || ch>= 'a' && ch<= 'z')

nletter++;

else if (ch>= '0' && ch<= '9')

ndigit++;

else if (ch == ' ' || ch =='\n' || ch == '\t')

nspace++;

else nother++;

i++;

}

/* print counts */

printf("Letters: %d \tWhite spaces : %d", nletter, nspace);

printf(" Digits : %d \tOther chars : %d\n", ndigit, nother);

getch();

}


HOPE THIS HELP


thaufiq1: Thank you for helping me but I needed a Java program,
Gautam25arora: ok ohk
Similar questions