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 7508223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:38:37+00:00 2026-05-29T22:38:37+00:00

So I have to get scanf to read in a few strings that are

  • 0

So I have to get scanf to read in a few strings that are separated by spaces. However, I don’t know beforehand how many strings I need to read it it can be anywhere from 1 to 5, but I can’t seem to get scanf to stop trying to read after hitting enter in the input. I have tried doing the naive %s %s %s %s %s but as you can imagine after hitting enter after say just 1 or 2 words it still expects to read more in and then I also tried to do %s%*[^\n]%s%*[^\n]%s%*[\n]%s%*[\n]%s%*[^\n] so that it would try to stop after a new line character but that didn’t work either.

So what is the best way to get scanf to be able to have some optional input sections.

Thanks.

Edit: I know about strtok and fgets I was just looking to see if there was a way to do this with scanf

  • 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-05-29T22:38:38+00:00Added an answer on May 29, 2026 at 10:38 pm

    How about using fgets to read one line and then strotk / sscanf to parse it ? Then you’ll be able to decide how many strings the user has entered.

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

Sidebar

Related Questions

So I have a class that has the following member variables. I have get
I Have to get a movie from a PostgreSQL database that matches a given
I have an app that needs to scan a barcode to get a code
I have a C program which uses a scanf to read a number and
EDIT: I'm told that making you guys read means I get less attention. My
I have recently started to learn Ruby. I know that Ruby is a interpreted
I have written the following C code to get in a list of strings
Simple question for all you pragmatic object-oriented fellas. I have read many times to
I need a java method that will read command prompt output and store it
Suppose I was given a URL. It might already have GET parameters (e.g. http://example.com/search?q=question

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.