19 Eylül 2013 Perşembe

C'de Dosya işlemleri

Sponsorlu Bağlantılar
#include<stdio.h>
int main()
{
    FILE *cfp,*fp2;
    char name[30],phone[20];
    int id;
    cfp=fopen("testPhone.txt","w"); // if no path is given, the file is put into the same directory as the source file...
    //if any other directory is needed, "D:/K:/testPhone.txt"
    printf("Enter name,phone,İd:\n");
    printf("Or EOF to end input\n ?");
    scanf("%s%s%d",name,phone,&id);
    
    while(!feof(stdin)) 
    {
                       fprintf(cfp,"%s %s %d\n",name,phone,id);
                       printf("?");
                       scanf("%s%s%d",name,phone,&id);
    }
    fclose(cfp);
    // now let us reopen the file for reading purpose
    fp2=fopen("testPhone.txt","r");
    while(!feof(fp2)) //açık olduğu müddetçe
    {
                      fscanf(fp2,"%s%s%d",name,phone,&id);
                      printf("%s %s %d\n",name,phone,id);
                      }
    system("pause");
    
}
Sponsorlu Bağlantılar

Hiç yorum yok:

Yorum Gönder