How To Print Large Amount of Data to File

Hello again,

In this example of my code, it will skip the first 3804 bytes of data and print Ô at the 3805 byte and 1 at the 3806 byte. I want to be able to write about 2500 more bytes past the 3806 byte. The characters in the data I want to print include everything from symbols to numbers even (") are included which would end the fputs command. Is there a way to do this?


Here's the code I'm working with...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>

int main(int argc, char **argv) {
const char *file;
const char *am;
FILE *fp;

printf("\n\nIOS Patcher v1.0 by Streamlinehd\n");
printf("Patch any IOS to v54321 or v65535\n\n");
if (argc != 3) {
fprintf(stderr, "Usage: %s IOS.wad [a]= Patch IOS version to v54321\n", argv[0]);
fprintf(stderr, "Usage: %s IOS.wad [b]= Patch IOS version to v65535\n", argv[0]);
return EXIT_FAILURE;
}

file = argv[1];
if (!(fp = fopen(file, "r+b"))) {
fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
return EXIT_FAILURE;
}
am = argv[2];
if( (argv[2][0] != 'a') && (argv[2][0] != 'b') )
{
printf("Incorrect Command can not patch. Please use [a]v54321/[b]v65535\n");
return EXIT_FAILURE;
}

if( (argv[2][0] == 'a')) {
fseek ( fp , 3804 , SEEK_SET );
fputs ( "Ô1" , fp );
}

fclose(fp);
printf("IOS Patched Successfully!");
return EXIT_SUCCESS;
}
hello streamline,

streamline wrote:
even (") are included which would end the fputs command
What do you mean by that? fputs doesn't end at " it ends at 0. Or do you want to end there?

fputs is good for strings. If you want to write binary use fwrite
Thanks for the reply coder777.

For example: fputs ( "Ô1" , fp ); - the data Ô1 will print but the " will not.

If I'm writing this much data (2500-bytes+) should I store it in a separate file (e.g. patch.data) and have the data go to buffer then use the buffer to write to the target file?
To put a " into a string, use a \ to escape it. fputs("\"",fp); will print a " into the file.
streamline wrote:
For example: fputs ( "Ô1" , fp ); - the data Ô1 will print but the " will not.
sure that doesn't since that quote doesn't belong to the string. "abc" is a c string which ends with 0. like rocketboy9000 stated if you want a quote within your string do what he says.

streamline wrote:
If I'm writing this much data (2500-bytes+) should I store it in a separate file (e.g. patch.data) and have the data go to buffer then use the buffer to write to the target file?
todays memory can easily hold 2500+ bytes. no need to make that file detour. (if I get it right)
Thanks guys! I really appreciate the help.
Topic archived. No new replies allowed.