Menyalin isi file ke file lain dengan bahasa C

Berikut adalah source code untuk operasi file menyalin isi file ke file lain

Alogaritmanya : program akan membaca isi file “baca.txt”, kemudian isi file tersebut akan ditulis pada file “salin.txt”, jika sebelumnya file “salin.txt” sudah ditulisi, maka isi sebelumnya akan dihapus.

#include <stdio.h>
#include <stdlib.h>

void main(){
FILE *baca, *salin;
baca = fopen("baca.txt", "a+");
salin = fopen("salin.txt", "w+");
char kar;
printf("menyalin file %s ke %sn", "baca.txt", "salin.txt");
while((kar=fgetc(baca))!=EOF)
fputc(kar,salin);
fclose(baca);
fclose(salin);
}

Semoga bermanfaat.
Salam, Penulis
Iin🙂

About Iin aryani

I don't wanna be a "Copycat" but, something they need to copy.

Posted on 24 January 2012, in Pemrograman C and tagged . Bookmark the permalink. Leave a comment.

Komentar untuk penulis

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: