Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:39:41+00:00 2026-06-17T22:39:41+00:00

I want to write a C program that tokenizes a string and prints it

  • 0

I want to write a C program that tokenizes a string and prints it out word by word, slowly, and I want it to simultaneously listen for the user pressing Enter, at which point they will be able to input data. Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:39:42+00:00Added an answer on June 17, 2026 at 10:39 pm

    Update: see @modifiable-lvalue ‘s comment below for additional helpful information, e.g., using getchar() instead of getch(), if you go that route.


    Definitely possible. Just be aware that gets() may not be entirely helpful for this purpose, since gets() interprets enter not as enter per se, but as “now, I the user, have entered as much string as I want to”. So the input gathered by gets() from pressing just an enter will appear as an empty string (which might be workable for you).
    See: http://www.cplusplus.com/reference/cstdio/gets/.
    But there are other reasons not to use gets()–it does not let you specify a maximum to read in, so it’s easy to overflow whatever buffer you are using. A security and bug nightmare waiting to happen. So you want fgets(), which allows you to specify a maximum size to read in. fgets() will place a newline in the string when an enter is pressed. (BTW, props to @jazzbassrob on fgets()).

    You could also consider something like getch()–which really deals with individual key-presses (but it gets a bit complicated handling keys that have non-straightforward scan-codes). You may find this example helpful: http://www.daniweb.com/software-development/cpp/code/216732/reading-scan-codes-from-the-keyboard. But because of the scancodes issues, getch() is subject to platform details.

    So if you want a more portable approach, you may need to use something heavier weight, but fairly portable, such as ncurses.

    I suspect you can do what you want with either fgets(), keeping in mind that enter will give you a string with just a newline in it, or getch().

    I just wanted you to be aware of some of the implementation/platform issues that can arise.

    C can absolutely do this, but it’s a little more complicated than one might guess at first attempt. That’s because terminal input is, historically, very platform dependent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a program that would take a string, let's say Fox
I want to write a program that sets cold to true if the user
I want to write a java program that acts as a user interface to
I want to write a simple program that determines whether the number the user
I want to write a Windows program that runs in the background and prints
I want to write a program that could play solitaire on windows. The user
I want to write a program in C that displays each word of a
I want to write a program that will take substrings from a given string.
I want to write a program that allows user to select one SQL Server
I want to write a program that asks the user a series of questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.