Monday, June 11, 2012

Operasi File di Bahasa C : Contoh Program


#include<stdio.h>
#include<conio.h>
char kata[10];
FILE *payjo;

int buka()
{




payjo=fopen("algo.txt","w");
fprintf(payjo,"Akupadamu",kata);
printf("\nSelesai....");
fclose(payjo);
}

int baca()
{
 payjo=fopen("algo.txt","r");
fscanf(payjo,"%s",&kata);
printf("\n%s",kata);
printf("\nselesai sudah....");
fclose(payjo);
}
int menu()
{
printf("Menu File\n");
printf("1. Buka file\n");
printf("2. Baca file\n");
printf("3. Keluar\n");
printf("Pilih[1-3]: ");
}

int main()
{
int pilih;
while(pilih !=3)
{
clrscr();
menu();
scanf("%d",&pilih);
switch(pilih)
{
case 1: {buka();getch();break;}
case 2: {baca();getch();break;}
case 3: {printf("Keluar");break;}
default: printf("salah pilih");getch();break;
}
}
return 0;
}

1 comment:

Note: Only a member of this blog may post a comment.