Skip to main content
edited tags
Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56
added 229 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23

#include <stdio.h>

#include <stdlib.h>

//int main(int argc, char* argv[])

int main(void) { // TODO int count=0; char name[8];

#include <stdio.h>

#include <stdlib.h>


//int main(int argc, char* argv[])

int main(void)
{    // TODO
    int count=0;
    char name[8];

    unsigned char buffer[512]={0};
    FILE * outptr=NULL;
    FILE* inptr=fopen("card.raw","r");
    if(inptr==NULL)
    {
        printf("nao foi possivel abrir o arquivo");
        return 1;
    }
    while(fread(buffer , sizeof(buffer) , 1 ,inptr))
    {
              // fread(buffer , sizeof(buffer) , 1 ,inptr);
         fwrite(buffer, sizeof(buffer) , 1, outptr);
        if(((buffer[0]==0xff) && (buffer[1]=0xd8) && 

(buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1) || (buffer[3]==0xe2) || (buffer[3]==0xe3) || ( buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) || (buffer[3]==0xe7) || (buffer[3]==0xe8) || (buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || (buffer[3]==0xec) || (buffer[3]==0xed) || (buffer[3]==0xee) || (buffer[3]==0xef))

(buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1)
        || (buffer[3]==0xe2) || (buffer[3]==0xe3) || (
buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) 
        || (buffer[3]==0xe7) || (buffer[3]==0xe8) || 
(buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || 
        (buffer[3]==0xec) || (buffer[3]==0xed) || 
(buffer[3]==0xee) || (buffer[3]==0xef))

        {
            if(outptr!=NULL)
            {
                fclose(outptr);
               // outptr=NULL;
            }
            sprintf(name, "%03d.jpg",count);
          //count++;
            outptr=fopen(name, "a");// outptr=fopen(jpg_name,w);
            fwrite(buffer, sizeof(buffer) , 1, outptr);
            count++;
        }
               else  if(outptr != NULL)
           { 
               fwrite(buffer, sizeof(buffer) , 1, outptr);
           }
             }

fclose(outptr);


   fclose(outptr);

    fclose(inptr);

    return 0;
}

}

#include <stdio.h>

#include <stdlib.h>

//int main(int argc, char* argv[])

int main(void) { // TODO int count=0; char name[8];

unsigned char buffer[512]={0};
FILE * outptr=NULL;
FILE* inptr=fopen("card.raw","r");
if(inptr==NULL)
{
    printf("nao foi possivel abrir o arquivo");
    return 1;
}
while(fread(buffer , sizeof(buffer) , 1 ,inptr))
{
          // fread(buffer , sizeof(buffer) , 1 ,inptr);
     fwrite(buffer, sizeof(buffer) , 1, outptr);
    if(((buffer[0]==0xff) && (buffer[1]=0xd8) && 

(buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1) || (buffer[3]==0xe2) || (buffer[3]==0xe3) || ( buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) || (buffer[3]==0xe7) || (buffer[3]==0xe8) || (buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || (buffer[3]==0xec) || (buffer[3]==0xed) || (buffer[3]==0xee) || (buffer[3]==0xef))

    {
        if(outptr!=NULL)
        {
            fclose(outptr);
           // outptr=NULL;
        }
        sprintf(name, "%03d.jpg",count);
      //count++;
        outptr=fopen(name, "a");// outptr=fopen(jpg_name,w);
        fwrite(buffer, sizeof(buffer) , 1, outptr);
        count++;
    }
           else  if(outptr != NULL)
       { 
           fwrite(buffer, sizeof(buffer) , 1, outptr);
       }
         }

fclose(outptr);

fclose(inptr);

return 0;

}

#include <stdio.h>

#include <stdlib.h>


//int main(int argc, char* argv[])

int main(void)
{    // TODO
    int count=0;
    char name[8];

    unsigned char buffer[512]={0};
    FILE * outptr=NULL;
    FILE* inptr=fopen("card.raw","r");
    if(inptr==NULL)
    {
        printf("nao foi possivel abrir o arquivo");
        return 1;
    }
    while(fread(buffer , sizeof(buffer) , 1 ,inptr))
    {
              // fread(buffer , sizeof(buffer) , 1 ,inptr);
         fwrite(buffer, sizeof(buffer) , 1, outptr);
        if(((buffer[0]==0xff) && (buffer[1]=0xd8) && 
(buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1)
        || (buffer[3]==0xe2) || (buffer[3]==0xe3) || (
buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) 
        || (buffer[3]==0xe7) || (buffer[3]==0xe8) || 
(buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || 
        (buffer[3]==0xec) || (buffer[3]==0xed) || 
(buffer[3]==0xee) || (buffer[3]==0xef))

        {
            if(outptr!=NULL)
            {
                fclose(outptr);
               // outptr=NULL;
            }
            sprintf(name, "%03d.jpg",count);
          //count++;
            outptr=fopen(name, "a");// outptr=fopen(jpg_name,w);
            fwrite(buffer, sizeof(buffer) , 1, outptr);
            count++;
        }
               else  if(outptr != NULL)
           { 
               fwrite(buffer, sizeof(buffer) , 1, outptr);
           }
             }

   fclose(outptr);

    fclose(inptr);

    return 0;
}
deleted 227 characters in body
Source Link

just a quick one, as a new b in c. my program is giving more than 1000 jpg for pset 4#include <stdio. please I have been using the code bellowh>

/** #include <stdlib.h>

  • recover.c
  • Computer Science 50
  • Problem Set 4
  • Recovers JPEGs from a forensic image. */ #include <stdio.h> #include <stdlib.h>

//int main(int argc, char* argv[]) int

int main(void) {    // TODO int count=0; char name[8]; unsigned char buffer[512]={0}; FILE * outptr=NULL; FILE* inptr=fopen("card.raw","r"); if(inptr==NULL) { printf("nao foi possivel abrir o arquivo"); return 1; } while(fread(buffer , sizeof(buffer) , 1 ,inptr)) { // fread(buffer , sizeof(buffer) , 1 ,inptr); fwrite(buffer, sizeof(buffer) , 1, outptr); if(((buffer[0]==0xff) && (buffer[1]=0xd8) &&

unsigned char buffer[512]={0};
FILE * outptr=NULL;
FILE* inptr=fopen("card.raw","r");
if(inptr==NULL)
{
    printf("nao foi possivel abrir o arquivo");
    return 1;
}
while(fread(buffer , sizeof(buffer) , 1 ,inptr))
{
          // fread(buffer , sizeof(buffer) , 1 ,inptr);
     fwrite(buffer, sizeof(buffer) , 1, outptr);
    if(((buffer[0]==0xff) && (buffer[1]=0xd8) && 

(buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1) || (buffer[3]==0xe2) || (buffer[3]==0xe3) || (  buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) || (buffer[3]==0xe7) || (buffer[3]==0xe8) ||    (buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || (buffer[3]==0xec) || (buffer[3]==0xed) ||    (buffer[3]==0xee) || (buffer[3]==0xef)) { if(outptr!=NULL) { fclose(outptr); // outptr=NULL; } sprintf(name, "%03d.jpg",count); //count++; outptr=fopen(name, "a");// outptr=fopen(jpg_name,w); fwrite(buffer, sizeof(buffer) , 1, outptr); count++; } else if(outptr != NULL) { fwrite(buffer, sizeof(buffer) , 1, outptr); }

    {
        if(outptr!=NULL)
        {
            fclose(outptr);
           // outptr=NULL;
        }
        sprintf(name, "%03d.jpg",count);
      //count++;
        outptr=fopen(name, "a");// outptr=fopen(jpg_name,w);
        fwrite(buffer, sizeof(buffer) , 1, outptr);
        count++;
    }
           else  if(outptr != NULL)
       { 
           fwrite(buffer, sizeof(buffer) , 1, outptr);
       }
         }

fclose(outptr); fclose(inptr); return 0;

fclose(inptr);

return 0;

}

just a quick one, as a new b in c. my program is giving more than 1000 jpg for pset 4. please I have been using the code bellow

/**

  • recover.c
  • Computer Science 50
  • Problem Set 4
  • Recovers JPEGs from a forensic image. */ #include <stdio.h> #include <stdlib.h>

//int main(int argc, char* argv[]) int main(void) {  // TODO int count=0; char name[8]; unsigned char buffer[512]={0}; FILE * outptr=NULL; FILE* inptr=fopen("card.raw","r"); if(inptr==NULL) { printf("nao foi possivel abrir o arquivo"); return 1; } while(fread(buffer , sizeof(buffer) , 1 ,inptr)) { // fread(buffer , sizeof(buffer) , 1 ,inptr); fwrite(buffer, sizeof(buffer) , 1, outptr); if(((buffer[0]==0xff) && (buffer[1]=0xd8) && (buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1) || (buffer[3]==0xe2) || (buffer[3]==0xe3) || (buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) || (buffer[3]==0xe7) || (buffer[3]==0xe8) ||  (buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || (buffer[3]==0xec) || (buffer[3]==0xed) ||  (buffer[3]==0xee) || (buffer[3]==0xef)) { if(outptr!=NULL) { fclose(outptr); // outptr=NULL; } sprintf(name, "%03d.jpg",count); //count++; outptr=fopen(name, "a");// outptr=fopen(jpg_name,w); fwrite(buffer, sizeof(buffer) , 1, outptr); count++; } else if(outptr != NULL) { fwrite(buffer, sizeof(buffer) , 1, outptr); }

}

fclose(outptr); fclose(inptr); return 0; }

#include <stdio.h>

#include <stdlib.h>

//int main(int argc, char* argv[])

int main(void) {  // TODO int count=0; char name[8];

unsigned char buffer[512]={0};
FILE * outptr=NULL;
FILE* inptr=fopen("card.raw","r");
if(inptr==NULL)
{
    printf("nao foi possivel abrir o arquivo");
    return 1;
}
while(fread(buffer , sizeof(buffer) , 1 ,inptr))
{
          // fread(buffer , sizeof(buffer) , 1 ,inptr);
     fwrite(buffer, sizeof(buffer) , 1, outptr);
    if(((buffer[0]==0xff) && (buffer[1]=0xd8) && 

(buffer[2]==0xff) && (buffer[3]==0xe0)) || (buffer[3]==0xe1) || (buffer[3]==0xe2) || (buffer[3]==0xe3) || (  buffer[3]==0xe4) || (buffer[3]==0xe5) || (buffer[3]==0xe6) || (buffer[3]==0xe7) || (buffer[3]==0xe8) ||  (buffer[3]==0xe9)|| (buffer[3]==0xea)|| (buffer[3]==0xeb) || (buffer[3]==0xec) || (buffer[3]==0xed) ||  (buffer[3]==0xee) || (buffer[3]==0xef))

    {
        if(outptr!=NULL)
        {
            fclose(outptr);
           // outptr=NULL;
        }
        sprintf(name, "%03d.jpg",count);
      //count++;
        outptr=fopen(name, "a");// outptr=fopen(jpg_name,w);
        fwrite(buffer, sizeof(buffer) , 1, outptr);
        count++;
    }
           else  if(outptr != NULL)
       { 
           fwrite(buffer, sizeof(buffer) , 1, outptr);
       }
         }

fclose(outptr);

fclose(inptr);

return 0;

}

Source Link
Loading