Results 1 to 6 of 6
Hi all,
I wanted to created file names dynamically,
so i tried something like this,
fun(){
int dy=97;
while(cond){
---
----
name[0]='n';name[1]='m';name[2]='a';
name[3]=dy;
//so i got nmaa
open (file)
//do ...
- 04-09-2007 #1
How to dynamically create file names?
Hi all,
I wanted to created file names dynamically,
so i tried something like this,
fun(){
int dy=97;
while(cond){
---
----
name[0]='n';name[1]='m';name[2]='a';
name[3]=dy;
//so i got nmaa
open (file)
//do something
close(file)
}
---
---
but the problem is i can created file names like,
nmaa,nmab,nmac,namd.........namz.
only upto z...
how to dynamically create unique file name?
If you know some other logic or solution please help me.
Thanks.
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 04-09-2007 #2
- 04-09-2007 #3Just Joined!
- Join Date
- Jan 2007
- Posts
- 23
creating files....
a unique filename can be generated by tmpnam() function.
if the temporary file is to be used immediately you can name it and open it
uing tmpfile() function.
#include<stdio.h>
int main()
{
char tmpname[L_tmpnam];
char *filename;
FILE *tmpfp;
filename=tmpnam(tmpname);
printf("Temporary file name is:%s\n",filename);
tmpfp=tmpfile();
if(tmpfp)
printf("Opened a temporary file OK\n");
else
perror("Tmpfile");
exit(0);
}
- 04-09-2007 #4
Thanks guyz...i will try both and let you know result.
Thanks u
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 04-10-2007 #5
I'm sorry -- I was thinking 'bash shell', instead of 'C'...
(guess I wasn't paying attention...)
- 04-10-2007 #6
Hi,
in C too we have mktemp see here- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote