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

  • Home
  • SEARCH
  • 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 9103819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:43:17+00:00 2026-06-17T01:43:17+00:00

I have a little bit of a problem while understanding the sscanf string formatting.

  • 0

I have a little bit of a problem while understanding the sscanf string formatting.

I have that string stored in str: 192.168.0.100/act?bla=

I want with this code to have bla stored inside my “key” variable and the remaining stuff (after the ‘=’) in my “buf” variable

char str[] = "192.168.0.100/act?bla=";
char key[20];
char buf[100];
sscanf(str, "%*[^?] %[^=] %s", key, buf);
  • 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-17T01:43:18+00:00Added an answer on June 17, 2026 at 1:43 am

    The ? and = will not be consumed so include them in the format specifier:

    sscanf(str, "%*[^?]?%[^=]=%s", key, buf);
    

    See demo at http://ideone.com/YoRMh3 .

    To prevent buffer overrun specify the maximum number of characters that can be read by each specifier, one less than the target array to allow for null termination, and ensure that both arrays were populated by checking the return value of sscanf():

    if (2 == sscanf(str, "%*[^?]?%19[^=]=%99s", key, buf))
    {
        printf("<%s>\n", key);
        printf("<%s>\n", buf);
    }
    

    In order to ensure that the buf value is not truncated, you can use the %n format specifier that populates an int indicating the position at which processing stopped (note the %n has no effect on the return value of sscanf()). If the entire input was processed the end position is strlen(str):

    int pos;
    if (2 == sscanf(str, "%*[^?]?%19[^=]=%5s%n", key, buf, &pos) &&
        strlen(str) == pos)
    {
        printf("<%s>\n", key);
        printf("<%s>\n", buf);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have little bit of problem while working with External entity reference in External
So I have a little bit of a problem. I working on a project
I am little bit confused about following problem & their solutions: i have 2
I have a little bit of Javascript that almost works correctly. Here's the code:
I have an application that captures keystrokes. But i have read a little bit
I have a MySQL query that I would like to optimize a little bit.
I have a repeater of div's that look a little bit like this: <div
I am facing a situation that I have problem understanding... I am writing a
hi there a have a little problem with printf while using threads. problem is
I have little bit longer question for you - but hope answer will be

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.