Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <cs50.h>
- #include "bmp.h"
- #define SIZE 5
- int main (int argc, char *argv[])
- {
- printf("Hello, World\n");
- FILE *file_input = fopen(argv[1], "r");
- if (file_input == NULL)
- {
- printf("Cannot open file\n");
- return 1;
- }
- BYTE buffer[SIZE];
- int count = 0;
- int n = 0;
- char file_name[4];
- sprintf(file_name, "%03i.txt", n);
- FILE *text_file = fopen(file_name, "w");
- while(fread(buffer, sizeof(buffer), 1, file_input) == 1)
- {
- count++;
- printf("The first char is %#02x and second char is %#02x\n",buffer[0],buffer[1]);
- if (buffer[0] == 0x68 && buffer[1] == 0x2c)
- {
- printf("True\n");
- if (n == 0)
- {
- fwrite(buffer, sizeof(buffer), 1, text_file);
- n++;
- } // end of if
- if (n != 0)
- {
- fclose(text_file);
- sprintf(file_name, "%03i.txt", n);
- text_file = fopen(file_name, "w");
- n++;
- }
- fwrite(buffer, sizeof(buffer), 1, text_file);
- }
- if (n > 0)
- {
- fwrite(buffer, sizeof(buffer), 1, text_file);
- }
- } // End of card reading
- int size_buffer = sizeof(buffer);
- printf("The size of buffer is %i\n",size_buffer);
- printf("The number of loop run is %i\n",count);
- fclose(text_file);
- fclose(file_input);
- } // End of main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement