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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:31:18+00:00 2026-06-14T10:31:18+00:00

In C, I want to create and open text files to write data into,

  • 0

In C, I want to create and open text files to write data into, but the problem is I want to name the files on the go, such as

FILE *ptr;

for(i=0;i<1000;i++){
   fopen_s(&ptr,"i.txt","w");
   operations to fill data into file i.txt;
   fclose(ptr);
}

such that I will create file 0.txt, 1.txt, 2.txt … 999.txt.

How is this possible? I checked open and rename functions, but couldn’t find a way to do.

Thank you so much for all your help.
Best,

  • 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-14T10:31:20+00:00Added an answer on June 14, 2026 at 10:31 am

    use snprintf to set the file number:

    FILE *ptr;
    char name[FILENAME_MAX];
    
    for(i=0;i<1000;i++){
       snprintf(name, sizeof(name), "%d.txt", i);
       fopen_s(&ptr, name, "w");
       //operations to fill data into file i.txt;
       fclose(ptr);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create and open a file but only if it doesnt exist.
I want to read a String (Data) out of a text file and write
What I want open a file if it exists, create it if it not
I want my program to open a file if it exists, or else create
I want to create a file, save data and then append some information to
I can't seem to open and write to a text file from my CGI
I want to create a binary file and store string data in it, I
i'm working on a task that i want to convert text file into PDF
I want to create my own IM and I'm searching an open-source IM APIs.
I want to create an extremely simple iPhone program that will open a telnet

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.