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

The Archive Base Latest Questions

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

Say If i want an input to be [Name] [Name] How would I detect

  • 0

Say If i want an input to be

[Name] [Name]

How would I detect

[Name] [Name] [Name] 

and return error?

Here is what I have so far,

char in[20];
char out[20];
scanf(" %s %s", out, in);
  • 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-22T01:37:38+00:00Added an answer on May 22, 2026 at 1:37 am

    This is homework, so you might be required to work under certain (arbitrary) restrictions. However, the phrase “scanf error handling” is something of an oxymoron in the C programming language.

    The best way to do this is to read in a line/other suitable chunk and parse it with C string functions. You can do it in one line of scanf but there are many drawbacks:

    1. You can guard against buffer overflows, but if a buffer isn’t large enough you can’t recover.
    2. You can specify specific character ranges for your strings, but it starts to look a little regexy, and the behavior of the "%[" format of scanf isn’t mandated in the standard.
    3. You can check for a third name, but the code looks unintuitive – it doesn’t look like you only want two names, it looks like you want three. scanf also gives you very little control over how you handle whitespace.

    EDIT: I initially thought from your question that the names were contained in brackets (a la "[Bruce] [Wayne]") but it now appears that was merely your convention for denoting a placeholder.

    Anyway, despite my intense dislike of scanf, it has its uses. The biggest killer (for me) is the inability to distinguish between line endings and simple space separation. To fix that, you can call fgets to read the data into a buffer, then call sscanf on the buffer. This gives you both a) safer reading (scanf messes with the ability of other more straightforward functions to read from a buffer) and b) the benefits of scanf formats.

    If you have to use scanf, your format basically be this:

    " %s %s %s"
    

    With the third being undesirable. As @Constantinius‘s answer shows, you’d need to read data into three buffers, and check whether or not the third passed. However, if you’re reading multiple consecutive lines of this data, then the first entry of the next line would satisfy the third slot, falsely giving you an error. I highly recommend using fgets and sscanf or ditching the sscanf for more precise manual parsing in this case.

    Here’s a link to the fgets man page if you missed the one I snuck in earlier. If you decide to ditch sscanf, here are some other functions to look into: strchr (or strspn, or strcspn) to find how long the name is, strcpy or memcpy (but please not strncpy, it’s not what you think it is) to copy data into the buffers.

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

Sidebar

Related Questions

Say I want to have an input form where one of the inputs is
Let's say that I have a line with: a = input(Enter your name and
Say I have an input field lastname, but I don't want people to insert
Say I want to draw a Ball in the scene and here are two
Say I want to have a method that takes any kind of number, is
I have have a simple HTML form with say four input widgets (see below)...two
I have an input value that I need to use to build out an
Let's say I have a Posts table and a Comments table. I want my
Let's say I have a drive such as C:\ , and I want to
I have the following DOM structure.. <input id=WorkAssignmentID_3462 type=hidden value=3462 name=WorkAssignmentID/> <input id=WorkItemID_3462 type=hidden

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.