Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-05
9
Medium Priority
?
792 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 switch statements in the C programming language.
Suggested Courses

610 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