Solved

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

Posted on 2004-04-05
9
777 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:vasureddym
ID: 10755805
hi sunny!

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

-vasu
0
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

726 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