/* Program to count number of characters, words and lines in a string */ /* Problem 22 */ #include #include #include main() { char str[255]; int c,w,l; int i,len; clrscr(); printf("Please enter your paragraph below : (press twice to stop)"); c = 0; w = 0; l = 0; printf("\n\n"); while (strlen(gets(str)) > 0) { len = strlen(str); c += len; for (i = 0; i < len; i++) { if (str[i] == ' ') w++; } l++; w++; } printf("%s",str); printf("Characters = %d, words = %d and lines = %d",c,w,l); printf("\n\nPress any key to exit..."); getch(); }