r/C_Programming • u/NeedleworkerClean445 • 25d ago
Feedback wanted: parsing JPEG segments byte by byte in C (my first binary-format project)
Enable HLS to view with audio, or disable this notification
Hello, I'm fairly new to C. I wanted to work on a project, so I decided to make metastrip to learn how a binary file format is parsed byte by byte.
I know ExifTool already exists and this isn't meant to compete with it, I did it to learn.
AI use: I wrote all the logic myself. AI reviewed my code (which means when I was done writing a particular function, I let AI review my code pick out bugs and any bad coding practices, based on the comments I would manually fix the issue without any assistance from AI for logic), generated test inputs, and wrote the --help text and the README.
This is the loop that walks the segments (trimmed, with ... where I left parts out):
while(1){
byte1 = getc(file);
byte2 = getc(file);
if(byte1 == 0xFF && byte2 == 0xDA && valid_targets[21] == 1){
/* start of scan: search backwards from the end of the file
for the last FF D9 to find trailing data */
...
break;
}
if(byte1 == EOF || byte2 == EOF) break;
int high = getc(file);
int low = getc(file);
unsigned int length = (high << 8) | low;
if (length < 2){
fprintf(stderr, "Segment length is incorrect\n");
break;
}
/* if the marker is a selected APPn / COM segment: print its payload */
...
else
fseek(file, length-2, SEEK_CUR); // not selected: skip the payload
}
metastrip can show all the APP segments, show only the segments you pick, strip them off, and hex dump them if you want.
I think I made one big mistake: I wrote everything in one file, main.c, which is now about 1,600 lines. Any tips on that would be nice, so I can improve the code in the future, and any tips on my coding practices in general.
I released v1.1.0 on GitHub, with a Windows build. If you'd like to see the code, it's here:
https://github.com/zyan-007/metastrip
I have recorded a demo video, kinda edited it too much now it looks like an ad, but it's just a demo
I'd appreciate any feedback on the code, structure or approach, including harsh feedback (please don't be too harsh...).
•
u/AutoModerator 25d ago
Hi /u/NeedleworkerClean445,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
You can read more at How do I post my Project?
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/mikeblas 24d ago
I think you want to work on a couple of things:
main()function has a ton of code. split it out7
u/AmanBabuHemant 24d ago
I have doubt that AI only wrote your --help option text, are you sure while making this statement ?
1
u/floatfloatjam 23d ago
Thank you for disclosing your AI usage. Valid use case imo