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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:21:18+00:00 2026-05-27T03:21:18+00:00

I would want to know how is it possible to escape %*s in a

  • 0

I would want to know how is it possible to escape “%*s” in a sprintf call.
For example I have the following piece of code:

sprintf(log_buffer,"1234 567 89");

strcpy(format,"%*s"); 

sprintf(format1, " %%%ds %%%ds ",5,5); 

printf("\n Format is : %s ",format); 

printf("\n Format1 is : %s ",format1); 

strcat(format,format1); 

printf("\n new format is : %s ",format); 

sscanf(log_buffer,format,name,name1);

printf(" Name is 1: %s \n",name);

printf(" Name is 2: %s ",name1);

This works fine.

It gives me:

Format is : %*s 

Format1 is : %5s %5s

new format is : %*s %5s %5s

Name is 1: 567 

Name is 2: 89

Can I possibly not use strcpy and ignore the %*s within the sprintf itself? I tried escaping it inside sprintf but I guess it’s not proper as I get a Segmentation fault.

sprintf(format1, " \%*s %%%ds %%%ds ",5,5);
  • 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-27T03:21:18+00:00Added an answer on May 27, 2026 at 3:21 am

    It looks like you already know how to escape % signs in sprintf (by prefixing with another %) – you’re doing it correctly for %%%ds.

    What you want is:

    sprintf(format1, " %%*s %%%ds %%%ds ",5,5);
    

    Edit: The reason it’s segfaulting is because \%*s is interpreted as a literal backslash, followed by a NULL-terminated string; so sprintf is trying to interpret 5 as a NULL-terminated string, which it patently isn’t. It’ll be running off into forbidden memory looking for a NULL-byte, and segfaulting.

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

Sidebar

Related Questions

i would want to know if is it possible to clear the form data
I want to know if it's possible to have the script detect the URL
I have a query and I just want to know if its possible to
I'm experimenting with Android and I want to know if the following is possible:
I know that with a large site you would want to separate footers, menus,
I would like to know a way (of course I want to know the
I would like to deepen my understanding of data types and want to know
I would like to know what I can offer to clients when they want
Hello I would like to know if my script is good; I want to
I would want to search up, down, and match case if possible. Even links

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.