473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

file related

how we create multiple file with diffrent name in c program?

Oct 30 '07 #1
3 1397
co*********@rediff.com said:
how we create multiple file with diffrent name in c program?
See K&R2 pp160-162

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 30 '07 #2
co*********@rediff.com wrote:
>
how we create multiple file with diffrent name in c program?
/* BEGIN new.c */

#include <stdio.h>
#include <stdlib.h>

#define NFILES 3
#define MAX_LINES_PER_FILE 15
#define LU_RAND_SEED 0LU
#define LU_RAND(S) ((S) * 69069 + 362437 & 0XFFFFFFFFLU)
#define NMEMB(A) (sizeof (A) / sizeof *(A))

void fremove(char (*fn)[L_tmpnam], size_t nmemb);

int main(void)
{
long unsigned index, lu_seed, line;
int rc;
char fn[NFILES][L_tmpnam];
FILE *fp;

puts("/* BEGIN new.c output */\n");
/*
** Open temporary input text files for writing.
** Close each file after filling with long unsigned values.
*/
lu_seed = LU_RAND_SEED;
for (index = 0; index != NMEMB(fn); ++index) {
tmpnam(fn[index]);
fp = fopen(fn[index], "w");
if (fp == NULL) {
fremove(fn, index);
puts("fopen(fn[index], \"w\") == NULL");
exit(EXIT_FAILURE);
}
printf("\"%s\" open for writing.\n", fn[index]);
line = lu_seed % MAX_LINES_PER_FILE + 1;
while (line-- != 0) {
lu_seed = LU_RAND(lu_seed);
fprintf(fp, "%lu\n", lu_seed);
printf( "%lu\n", lu_seed);
}
fclose(fp);
printf("\"%s\" closed.\n\n", fn[index]);
}
/*
** Open input text files for reading.
** Close each temp input file after reading.
** Remove temporary input files.
*/
for (index = 0; index != NMEMB(fn); ++index) {
fp = fopen(fn[index], "r");
if (fp == NULL) {
fremove(fn, NMEMB(fn));
puts("fopen(fn[index], \"r\") == NULL");
exit(EXIT_FAILURE);
}
printf("\"%s\" open for reading.\n", fn[index]);
while ((rc = getc(fp)) != EOF) {
putchar(rc);
}
fclose(fp);
printf("\"%s\" closed.\n\n", fn[index]);
}
fremove(fn, NMEMB(fn));
puts("\n/* END new.c output */");
return 0;
}

void fremove(char (*fn)[L_tmpnam], size_t nmemb)
{
while (nmemb-- != 0) {
if (remove(fn[nmemb]) == 0) {
printf("\"%s\" removed.\n", fn[nmemb]);
}
}
}

/* END new.c */

--
pete
Oct 30 '07 #3
co*********@rediff.com wrote:
how we create multiple file with diffrent name in c program?
Your question is not clear. There are many possibilities. One of them
involves adding a variable prefix or suffix to a chosen name. Another
possibility is to use tmpfile() function to open unique files.

If you describe the exact context of your problem we may be able to
suggest better solutions.

Oct 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sven | last post by:
Hello, I am receiving a text file that is produced from a mainframe that is out of my control. I am attempting to find a (hopefully clean) way to import it into a SQL Server database in an...
3
by: Abhas | last post by:
> > Hi, this is Abhas, > > I had made a video library program in C++, but was facing a problem. > > After entering 12 movies, i cannot enter any more movies. > > Something gibberish comes instead....
12
by: A.M. | last post by:
Hi at all, how can I do to insert into a HTML page a file .txt stored in the same directory of the server where is the html file that must display the text file.txt? Thank you very much P.Pietro
10
by: Dieter Salath? | last post by:
Hi, in our webpage, a user could open a windows explorer to his temp directory with a simple link and usage of the file protocol: <a href="file://C:\temp" target="_blank">C:\temp</a> This...
1
by: Mika M | last post by:
I have made Setup and Deployment Project for my application. This application uses couble of Crysral Report .rpt -files, so I included following into Setup and Deployment Project ... -...
2
by: Andrew Clark | last post by:
Hello, I am 99% sure that the problem I am having is not PHP related, but to remove my doubt, I am posting here. I have a search page (interfacing with MySql) that displays results in an...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
3
by: Steven Nagy | last post by:
Hi all, ASP.NET : Framework 2.0 - C# A recent addition to my code generater will create GridView's and ObjectDataSource's in a control (ASCX). So the code gen creates an ascx, ascx.cs,...
3
by: ooba gooba | last post by:
After doing some work in both Java and ASP.NET, I came back to add some major enhancements to a PHP 4 application I built several years ago. A lot of the database access is currently sprinkled...
1
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.