P
paul.lemelle
I am trying to create a series of 4K files, everything works fine
until I pass the 1022 mark - I get an error stating that he file
cannot be opened.
Can someone look at the below code and offer a suggestion for a
solution?
__
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE **fp;
char filename[50];
long i;
long count;
long number;
int k = 32000;
long datasize;
datasize = 4 * k;
printf("How many files to create: ");
scanf("%d\n", &number);
fp = malloc( sizeof(FILE *) * number);
if( fp != NULL )
{
for(i=0; i < number; i++)
{
sprintf(filename, "%s%d.txt", "file",i+1);
if( ( fp = fopen(filename, "a+") ) == NULL )
{
printf("Error: File \"%s\" cannot be opened\n", filename);
continue;
}
count = 0;
while (count < datasize)
{
fprintf(fp,"%s","1234567812345678123456781234678\n");
count ++;
}
//fclose(fp);
}
}
else
{
printf("Error: Not enough memory\n");
getchar();
return 1;
}
free(fp);
printf("All done\n");
getchar();
return 0;
}
until I pass the 1022 mark - I get an error stating that he file
cannot be opened.
Can someone look at the below code and offer a suggestion for a
solution?
__
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE **fp;
char filename[50];
long i;
long count;
long number;
int k = 32000;
long datasize;
datasize = 4 * k;
printf("How many files to create: ");
scanf("%d\n", &number);
fp = malloc( sizeof(FILE *) * number);
if( fp != NULL )
{
for(i=0; i < number; i++)
{
sprintf(filename, "%s%d.txt", "file",i+1);
if( ( fp = fopen(filename, "a+") ) == NULL )
{
printf("Error: File \"%s\" cannot be opened\n", filename);
continue;
}
count = 0;
while (count < datasize)
{
fprintf(fp,"%s","1234567812345678123456781234678\n");
count ++;
}
//fclose(fp);
}
}
else
{
printf("Error: Not enough memory\n");
getchar();
return 1;
}
free(fp);
printf("All done\n");
getchar();
return 0;
}