Skip to content

Latest commit

 

History

History
47 lines (24 loc) · 809 Bytes

Program to find no of token.md

File metadata and controls

47 lines (24 loc) · 809 Bytes

#include <stdio.h>

#include <stdbool.h>

int main()

{

char ch; int count = 0, tokenLength = 0;

bool isspace = true;

printf("Enter a sentence: ");

while ((ch= getchar()) != '\n') // Read the characters until a new line is found

{

if (ch=='') // If the character is a space

if (lisSpace) // End of a token

count++; // Increment the word count printf("Length of token %d: %d\n", count, tokenLength); tokenLength = 0; // Reset the length for the next token

isSpace = true;

} else // If the character is not a space

{ tokenLength++; // Increment the length of the current token isSpace = false;

}

if (lisSpace) // If the last character is not a space, count the last

{

word

}

count++;

printf("Length of token &d: %d\n", count, tokenLength);

printf("Number of tokens: %d\n", count);

return 0;