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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:24:54+00:00 2026-06-01T11:24:54+00:00

I need to parse a response from a server like this: risposta: 200\n Len

  • 0

I need to parse a response from a server like this:

risposta:

200\n
Len 1040\n
Expire 30\n
\n
1111111111111111111111111\n
1111111111111111111111111\n
1111111111111111111111111\n

I’m trying with sscanf:

sscanf(risposta, "%d\nLen %d\nExpire %d\n\n%s[^\0]", &risp->type, &risp->len, &risp->expire, risp->risorsa);

but it puts only 1111111111111111111111111 in risp->risorsa.
How to resolve?

P.s. struct risp:

typedef struct Server_risp {
   int type;
   int expire;
   int len;
   int sup;
   int inf;
   char risorsa[5000];
 }Server_risp;
  • 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-01T11:24:56+00:00Added an answer on June 1, 2026 at 11:24 am

    A scanset specification is not %s[whatever], it’s just %[whatever], so your format string should be more like: "%d\nLen %d\nExpire %d\n\n%[^\0]".

    As a side note, scanf and friend consider any white space in a format string is equivalent to any other whitespace — any whitespace in the format matches an arbitrary sequence of whitespace characters in the input (and a new-line is considered whitespace). Your current format string does a nice job of documenting the format you expect, but from a viewpoint of what it really matches, you can change it to something like: "%d Len %d Expire %d %[^\0]" without affecting what it’ll do. In particular, your two consecutive new-lines aren’t really accomplishing much.

    Edit: Thinking about it, the [\0] causes just a bit of a problem: the “\0” terminates the string, so you end up with an invalid scan-set specification. Since you just want the rest of the input to go into risorsa, it’s probably easiest to use %c: "%d Len %d Expire %d %4999c".

    And yes, this time I actually tested it:

    #include <stdio.h>
    
    char *riposta = "200\n"
        "Len 1040\nExpire 30\n"
        "\n1111111111111111111111111\n"
        "1111111111111111111111111\n"
        "1111111111111111111111111\n";
    
    typedef struct Server_risp {
        int type;
        int expire;
        int len;
        int sup;
        int inf;
        char risorsa[5000];
    }Server_risp;
    
    int main() {
        Server_risp risp;
       sscanf(riposta, "%d Len %d Expire %d %4999c", &risp.type, &risp.len, &risp.expire, risp.risorsa);
    
       printf("%s\n", risp.risorsa);
    }
    

    result:

    1111111111111111111111111
    1111111111111111111111111
    1111111111111111111111111
    

    Edit 2: I’m not sure exactly what problem you’re running into here. I modified it a bit to show reading both leading and embedded white-space:

    #include <stdio.h>
    
    char *riposta = "200\n"
    "Len 1040\nExpire 30\n"
    "|        |"
    "\n1111111111111111111111111\n"
    "1111111111111111111111111\n"
    "1111111111111111111111111\n";
    
    typedef struct Server_risp {
        int type;
        int expire;
        int len;
        int sup;
        int inf;
        char risorsa[5000];
    }Server_risp;
    
    int main() {
        Server_risp risp;
        sscanf(riposta, "%d Len %d Expire %d%4999c", &risp.type, &risp.len, &risp.expire, risp.risorsa);
    
        printf("%s\n", risp.risorsa);
    }
    

    …and got pretty much the expected result:

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

Sidebar

Related Questions

I am trying to parse a JSON response from a server using javascript/jquery. This
I am getting some response from server side which i need to parse but
I'm processing a response from the server using NSXMLParser successfuly. Something like this <data>
I need to parse the server response from my http post & puts. I
i need to parse this php xml response in android: <?phpxml version=1.0 encoding=utf-8?> <SmsResponse>
I am getting response from server side in the form of json array.I need
The JSON response we got from the server is already stringfied or we need
I am getting a response from server which I need to deserialize using protobuf.
Essentially, I need to parse the response string of the CHAT CREATE command with
I'm making http requests using winsock and I need to parse the response. The

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.