c++ program to alter bytes of an image file

zorrotech

Right off the assembly line
hey guys,
i was trying to write a c++ program to alter every 4th byte of an image file....
i want to replace every 4th byte in the file with a 7....
but the program doesnt seem to be working...can someone help me out with it....

this what i wrote:

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

void main()
{

DIR *dir; int c=-1; char buf[10];
char files[1000][1000];
struct dirent *ent;
dir = opendir ("d:\\test");
if (dir!= NULL) {
while ((ent = readdir (dir)) != NULL)
{
printf ("%s\n", ent->d_name);
strcpy(files[++c],ent->d_name);


}// retrieves names of files in the directory and puts them in the files array

for(int i=2;i<=c;i++)
{ fstream file(files, ios::in|ios::binary|ios::eek:ut);

while(file.eof()!=-1)
{
file.read(buf,sizeof(buf));
cout<<buf<<"\n";
for(int j=0;i<10;i++)
{ buf[j]=77777;i=i+2;
}
file.seekg(-10,ios::cur);

file.write(buf,sizeof(buf)); cout<<"\n"<<"written";
}
file.close();
}



closedir (dir);
} else {
/* could not open directory */
perror ("");
//return EXIT_FAILURE;
}
getch();
}
 
Last edited:
Top Bottom