Skip to content
Advertisement

Merging two text files into new one (back and forth every new line) using C in Linux using system-calls

So the assignment is merging two text files in Linux using system calls:

  • 1.txt:

Hello,

my class!

  • 2.txt:

Today is

a very nice

day

  • NEW.txt:

Today is

Hello,

a very nice

my class!

day

Problem is I get (sorry for putting this as code sample):

JavaScript

The + sign keeps changing between (“#”, “(“, “0”, “_”, ..) with each execution..

Why do I have extra new lines and this thing with the *? Thank you in advance.

My code:

JavaScript

Advertisement

Answer

you have to retain if you have read all your file or not, because the read in the first while will … read, and that’s not what you want.

Code edited after comment :

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement