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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:14:28+00:00 2026-06-13T13:14:28+00:00

I am displaying a partition table, and the table is displayed somewhat like: Number

  • 0

I am displaying a partition table, and the table is displayed somewhat like:

Number     Device name       Partition type      Size in MB
------------------------------------------------------------
1           /dev/sda1         NTFS                    300
2           /dev/sda2         *Win95 FAT32             99
3           /dev/sda3         Unknown                 128
4           /dev/sda4         NTFS                  19472
120         /dev/sda120       NTFS                   3000

*=Active partition

Now for displaying the above, we are using formatted output printf and the format string is

"%-6d=partition number    %-25.25s=device name  %c=active partition    %-30.30s=part type          %7Ld=size"

Now i want to display the same partition table, but with some slight modification, such that the gaps in partition slots would be displayed by a range, like:

5-119     /dev/sda5.../dev/sda119    Empty          0

I am using the formatted string as:

%d-%-6d=partition range   %s%d...%s%d=(/dev/sda5.../dev/sda119)   %c  %-30.30s  %7Ld

but it does not help me.

What should be the correct format string? I am using a gcc compiler.

  • 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-13T13:14:28+00:00Added an answer on June 13, 2026 at 1:14 pm

    I think you need to use snprintf() to prepare the two composite strings, and then a simpler printf() to do the actual printing. Since you’ve not shown your actual code, we have to guess at everything, which is a nuisance…

    int   min = 5;
    int   max = 119;
    char *dev = "/dev/sda";
    
    char  num_range[32];
    char  dev_range[60];
    
    snprintf(num_range, sizeof(num_range), "%d-%d", min, max);
    snprintf(dev_range, sizeof(dev_range), "%s%d...%s%d", dev, min, dev, max);
    
    printf("%-10s   %-50.50s   %c%-30.30s  %7d", num_range, dev_range, ' ', "Empty", 0);
    

    You specified %-25.25s for a single device, so it isn’t clear whether you should double that for the range, or you should use some other value (or even the same value); you’ll need to tweak that part of the format string to suit yourself. This technique is also how I get a colon at the end of a name — format the name and the colon into a string, and then format that string into the final print operation.

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

Sidebar

Related Questions

I am displaying mySQL in an html table. I would like to change the
Displaying Type here to ... until the user enters text into a TextBox is
When displaying all articles of a specific month (given through the urls like this
Displaying total number as text for multiple pins at the same location in map
When displaying my DateTime values, I want them to be formatted like so: February
Problem with displaying news from database! Screenshoot: Database(table) Articals: ID, Title, Content, User Very
While displaying the download status in a window, I have information like: 1) Total
I'm displaying my categories using the wp_list_categories function like so: <?php wp_list_categories('selected=6&title_li='); ?> Now,
I'm displaying a dynamic list of names in a table view, and I'm trying
I am displaying any size image to fit in a 175x175 frame so it

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.