heylo guys! im new here, just registered today!! yay!!!
ok im trying to write a program that takes an input file, reads its character by character and writes to a output file character by character.
now the problem is for example: input = 1 2 3 4 5, output = 1 2 3 4 5 4
and i really can't figure out why except maybe i dont know how to use feof...
here is the code, please help!!
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
char* infile = argv[1];
char* outfile = argv[2];
FILE* inptr = fopen(infile, "r");
FILE* outptr = fopen(outfile, "w");
int data;
while(!feof(inptr))
{
fread(&data, sizeof(int), 1, inptr);
fwrite(&data, sizeof(int), 1, outptr);
}
fclose(inptr);
fclose(outptr);
return 0;
}