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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:00:35+00:00 2026-05-12T12:00:35+00:00

Imagine the following: you read in a string with scanf() but you only need

  • 0

Imagine the following:

you read in a string with scanf() but you only need a few of the datapoints in the string.

Is there an easy way to throw away the extraneous information, without losing the ability to check if the appropriate data is there so you can still reject malformed strings easily?

example:

const char* store = "Get: 15 beer 30 coke\n";
const char* dealer= "Get: 8 heroine 5 coke\n";
const char* scream= "Get: f* beer 10 coke\n";

I want to accept the first string, but forget about the beer because beer is yuckie.
I want to reject the second and third strings because they are clearly not the appropriate lists for the 7/11;

So I was thinking about the following construction:

char* bId = new char[16];
char* cId = new char[16];
int cokes;
sscanf([string here], "Get: %d %s %d %s\n", [don't care], bId, &cokes, cId);

This way I would keep the format checking, but what would I put for [don’t care] that doesn’t make the compiler whine?

Of course I could just make a variable I don’t use later on, but that is not the point of this question. Also checking the left and right side seperately is an obvious solution I am not looking for here.

So, is there a way to not care about but still check the type of a piece of string in scanf and friends?

  • 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-12T12:00:35+00:00Added an answer on May 12, 2026 at 12:00 pm

    Use a * as assignment suppression character after %

    Example:

      sscanf([string here], "Get: %*d %s %d %s\n", bId, &cokes, cId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just read the following cqrs article . It makes perfect sense, but didn't
Imagine following situation: There is a distributed key/value database stored on computer network. One
Imagine following scenario: We have a lot of parallel development going on in several
Imagine the following class: class A { public event EventHandler AnyEvent; } You create
Imagine the following A type T has a field Company. When executing the following
Imagine the following REBOL code: foo: context [bar: 3] I now have a context
Imagine the following tables: create table boxes( id int, name text, ...); create table
Imagine the following table (called TestTable ): id somedate somevalue -- -------- --------- 45
Imagine the following database: Table 'companies' has fields id, name and flagship_product_id. Table 'products'
imagine the following environment: an XBAP application running in partial trust mode (default behaviour;

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.