The results are the same -- a character is read -- but comparing the two is a little hard since your comparing two different programing paradigms...I guess if you strip away the syntax and look at the low level results of the code...then yes the code is equivalent since both accomplish the same thing.
>I want to know the differences in between two?
That's a tough comparison. Can you be a little more specific?
>also is this code equivalent
No, the C code has two bugs (an uninitialized FILE pointer, and using char instead of int for the return value of fgetc). The C++ code is correct due to ifstream's constructor, but it won't do anything because the stream isn't attached to a file.
>Consider that the files are attached.
I'd still ask you to be specific, and the char bug for fgetc is still present.
>Actually i wanted to ask whether this correct
That's quite a bit different than "tell me all of the differences between FILE* and ifstream". :icon_rolleyes: And no, it's not correct. For reasons that I won't go into, stream objects aren't copyable. You need to pass by reference:
void encode_file (ifstream& fin, ofstream& fout)
Then it should work.
>ie they read and write a single byte at a time only (if ch is char type)
That's correct, but fgetc can also return EOF. It's for this reason that fgetc returns int rather than char.