Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below is my code in that i'm trying to create 1000 bmp images to represent some colors. i'm writing pixel values from loop values. output of this code generate only 508 images, if i set any for loop it again generate only 508 images.
my main goal is to create 16581375 images of all colors.
so please help me for this.

What I have tried:

#include<stdio.h>
#include<conio.h>

void main()
{
    FILE *fp,*pt;
    unsigned char b=66,c=77,aa[54],x=0,jjj=0,jjjj=0,jjjjj=0,buf[1000];
    unsigned short int d=0,v=1,u=24,o=16973;
    unsigned int g,k=0;
    unsigned long siz=102,i=0,r=0,n=0,s=0,l=1200054,h=54,e=54,f=40,q=4,w=4,a=0,z=0,m=200,ss=0,sss=0;//h=16581375,siz=497441304,w=10
    //printf("%c",b);
    i=0;

   for(i=0;i<10;i++)
    {

        for(r=0;r<10;r++)
        {

            for(n=0;n<10;n++)
           {
               //str=ss+str+stdr;
               sprintf(buf,"all%d.bmp",ss);
               fp=fopen(buf,"wb");
               fwrite(&b,sizeof(char),1,fp);
               fwrite(&c,sizeof(char),1,fp);
               fwrite(&siz,sizeof(long),1,fp);
               fwrite(&d,sizeof(short int),1,fp);
               fwrite(&d,sizeof(short int),1,fp);
               fwrite(&e,sizeof(long),1,fp);
               fwrite(&f,sizeof(long),1,fp);
               fwrite(&q,sizeof(long),1,fp);
               fwrite(&w,sizeof(long),1,fp);
               fwrite(&v,sizeof(short int),1,fp);
               fwrite(&u,sizeof(short int),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               fwrite(&a,sizeof(long),1,fp);
               fwrite(&a,sizeof(long),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               fwrite(&z,sizeof(long),1,fp);
               for(s=0;s<16;s++)
               {
                 fwrite(&i,sizeof(char),1,fp);
                 fwrite(&r,sizeof(char),1,fp);
                 fwrite(&n,sizeof(char),1,fp);

              }
              ss++;

            }

        }

     }

    getch();
}
Posted
Updated 21-Aug-18 10:29am
v2
Comments
RedDk 21-Aug-18 18:10pm    
I like how you think my friend. A quick 60 byte 1 x 1 pixel .bmp with 16581375 variations of RGB triad (comb/permute ... scheesch I remember doing this with QBASIC in a "codon" display at console twenty years ago ... just for the halibut) .. a very admirable task in C. S'gonna take more than a few 4GB drives to store (as OG said down there in the locker) ... but still admirable.
Rick York 22-Aug-18 0:19am    
Maybe in the sense that rarely do we such masochism.
KarstenK 22-Aug-18 4:20am    
Create so much files is stupid. It will hurt your systems performance severly and may lead to a system crash. So make a backup to protect your data.

If I read you right, you want to create a file for each of the possible colours that a bitmap can contain. That's not necessarily a problem, but the reason it doesn't work for you is that you are running out of file handles.
Because you don't close your files when you are finished with them, the system can't automatically release the handle for reuse, and you run out, so your app stops working properly.

Close your file when you are finished with it, and you can move on to the next problem you are going to meet ... running out of file names ... 64K is a max files-per-folder limit for FAT32, 300,000 is a limit for exFAT as you run out of 8.3 filenames, and search times go through the roof on the extended ones. You can get round this with separate folders, but ... then you meet the next problem: disk space.
16777216 files at 146 bytes each is bad enough: 2,449,473,536 bytes, but since each is a separate file, they will take an allocation unit each to store, and the chances are that each unit is 4096 bytes. So you will need at least 68,719,476,736 bytes free to store them...
 
Share this answer
 
Quote:
my main goal is to create 16581375 images of all colors.

The whole idea look very wrong to me.
Just because a directory is not sorted, finding a file involve reading sequentially all file names until you find the 1 you looking for. I fear it will be faster to build the file on fly for each request.
Quote:
output of this code generate only 508 images

May be you should learn how to write in files.
C++
fp=fopen(buf,"wb");

In C, you must close what you opened.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900