Question

Write a C program where user enter a string input, tokenizer the string using space character....

Write a C program where user enter a string input, tokenizer the string using space character. Calculate the lengh of string. Find word start. Find word end. Count words.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program

//preprocessor
#include <stdio.h>
//main function for executing the code
int main()
{
   //variable declaration
   int i,length=0,wordcount=0;
   //storing the string in a character array
    char str[]="today is sunday its a holiday";
    //running loop for accessing the each character in the string untill end of the string is encountered
    for(i=0;str[i] !='\0';i++){
       if(length==0){//printing the starting of the word
           printf("\nStart of word\n\"");
       }
       if(str[i]==' '){//if space character is encountered then count it as end of the word
               printf("\"\nEnd of word\n");//print the word has ended
               printf("\nStart of word\n\"");//starting new word
               wordcount++;//incrementing the counter for the words                  
       }
       else{
           printf("%c",str[i]);//print the character in the strings
       }
       length++;//count the length of the string
   }
   printf("\"\nEnd of word\n\n");//after encountering end of the file, print end of the word
   wordcount++;//increment word count as last word will not end by space instead by \0
  
   printf("String is: \"%s\"\n",str);//print the string used for tokenizing
   printf("Length of the string: %d\n",length);//print the length of the string
   printf("No of words: %d\n",wordcount);//print the number of word counted

    return 0;
}

Output:

E:\Program\C & C++1StringToken.exe Start of word today End of word Start of word End of word Start of word sunday End of word Start of word its End of word Start of word End of word Start of word holiday End of word String is: today is sunday its a holiday Length of the string: 29 No of words: 6

Add a comment
Know the answer?
Add Answer to:
Write a C program where user enter a string input, tokenizer the string using space character....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ programming. Write a program that takes a string of input from the user and...

    Using C++ programming. Write a program that takes a string of input from the user and separates the string of words based on the premise that the string contains words whose first letter is uppercase. Then, display the phrase (or sentence) to a string in which the words are separated by spaces and only the first word of the phrase starts with an uppercase letter. For example, if the user enters "IAmTheTeacher", then the program would display: "I am the...

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

  • Using Java write a program that takes a string input from the user and then outputs...

    Using Java write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word.

  • Write a program in java to read a string object consisting 300 characters or more using...

    Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters.(Use String class methods). a, Determine the length of the string count the number of letters in the strings , count the number of numeric object d. Calculate the number of special character e. Compute the ratio of the numeric to the total f....

  • Write a C Program that asks the user to input a string and then the user...

    Write a C Program that asks the user to input a string and then the user is prompted back whether the input string is a “Palindrome Word” or not. (A Palindrome Word reads the same backward or forward, eg. madam, racecar, etc.) Your program should contain a function that accepts the input string from the main function and returns a value indicating whether the input string is a Palindrome or not. Use Pointers to traverse the string.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • PYTHON: write a program that lets the user enter a sting and displays te character that...

    PYTHON: write a program that lets the user enter a sting and displays te character that appears most frequently in the string. A space can be the most frequent in the string, but do not include it for the count. (Please make it as simple as possible, I just started learning python)

  • Java Letter Counter: Write a program that asks the user to enter a string, and then...

    Java Letter Counter: Write a program that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. Must use a do while loop and a counter!!!!

  • Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program...

    Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program #5-5). Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count. <END>

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT