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

The Archive Base Latest Questions

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

I have a file and I want to insert data in it as columns

  • 0

I have a file and I want to insert data in it as columns like this:

Column size: 5spaces 5spaces 12 spaces

25100 23501 169247103621

But I still have this two conditions:

  1. If the string bigger then the column size, I eliminate the odd
    length from the string.
  2. If the string smaller then the column size, I fill the rest of
    string with spaces.

Ex1:

2510025 23501 169247103621

Become:

25100 23501 169247103621

Ex2:

25 23501 169247103621

Become:

25    23501 169247103621

I manged to get this in c with printf, but now I want print some format in a file.

#include <stdio.h>


int main(int argc, char **argv)
{
   char FMT[] = "%-5.5s %5s %-6.12s\n";
   FILE *hFile = NULL;
   char *string  = "freeifaddrss";
   char *string2 = "cards";
   char *string3 = "ifa_nextifa_next";
   printf(FMT, string, string2, string3);
   return 0;
}
  • 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-14T15:51:15+00:00Added an answer on June 14, 2026 at 3:51 pm

    To write to a file you can either redirect the output of your program, eg:

    ./prog > out.txt
    

    or open a file in the program and write to that:

    FILE *f = fopen(argv[1], "w");
    if (f == NULL) {
         perror(argv[1]);
         exit(EXIT_FAILURE);
    }
    ...
    fprintf(f, FMT, string, string2, string3);
    

    Call this with:

    ./prog out.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to place one txt file (which have insert statements) of size 273
I have some data in a csv file and I want to insert it
I have a test file that contains 1,2,3 2,3,4 5,6,7 I want to insert
I have KML file and I want to read this file and to do
Assume that I have file XML like this : <?xml version=1.0?> <P> <Content> <id>1016576</id>
I have an XSLT file for transforming data from table to INSERT statements. So
I have a text file that I parse each month and insert the data
I have a .txt file which contains a column of unixtime, like (1322485992.420381000), the
I want to insert some session data in a database. I have one table
I want to insert data from included file and create HTML-elements automatically. In data.php

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.