Solved

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

Posted on 2004-04-05
9
773 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

707 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

17 Experts available now in Live!

Get 1:1 Help Now