Solved

automatic file renaming like file1, file2, file3, file4, so on.....

Posted on 2004-04-05
9
775 Views
Last Modified: 2010-04-15
hi all!
i need to dynamically update file names.

all i need is to have a string (file path) updated like file1, file2, file3,, so on.
could some one help me!!!!!!!!!

thanks in advance.
0
Comment
Question by:vasureddym
  • 4
  • 4
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10755696
Hi vasureddym,

man 3 mktemp

SYNOPSIS
       #include <stdlib.h>

       char *mktemp(char *template);

DESCRIPTION
       The  mktemp()  function  generates a unique temporary file
       name from template.  The last six characters  of  template
       must  be  XXXXXX and these are replaced with a string that
       makes the filename unique. Since it will be modified, tem­
       plate  must  not  be  a  string  constant,  but  should be
       declared as a character array.

Sunnycoder
0
 
LVL 2

Author Comment

by:vasureddym
ID: 10755717
sunnycoder,

that's ok but i need all files to have names sequentially like file1,file2,file3.

-vasu
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 100 total points
ID: 10755762
if you want to generate the names yourself

int i = 1;

char name[10];

while ( .. )
{
       snprintf ( name, 9, "file%d", i++ );
       fopen ( name, .. );
       ...
}
0
 
LVL 2

Author Comment

by:vasureddym
ID: 10755805
hi sunny!

i'm not able to find the library for the function "snprintf()"

-vasu
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Author Comment

by:vasureddym
ID: 10755806
hi sunny!

i'm not able to find the library for the function "snprintf()"

-vasu
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10755824
you do not link to the library explicitly .... it should be linked automatically ...
the function is delcares in stdio.h and is implemented in glibc

what is the error message you get ? ... Can you work with sprintf ?
0
 
LVL 2

Author Comment

by:vasureddym
ID: 10755884
sorry!
i read it as snprintf instead of sprintf.

it is working.


void main()
{
int i = 1;

char name[10];
clrscr();
for(;i<=4;i++)
{
       sprintf( name,"file%d", i );

      printf("\n%s", name);
}

getch();

}

. thanks sunny..
but a dought, what for did u use 9 in sprintf function?
thanks
-vasu
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10755898
That was actually snprintf ... snprintf is a safer version of sprintf in which you can specify the maximum length of string to be printed thereby avoiding risks of buffer overruns
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10756267
Hi vasureddym,
try _snprintf.

Cheers,
Stefan
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now