C Dosyalarda Veri Kaydetme Sorunu

NoWeDoR
Cool Çırak
Arkadaşlar telefon defteri programı yazmaya çalışıyorum. İlk fonksiyon (Bilgileri kaydeden fonksiyon)'u bitirdim. Program çalışıyor ancak kullanıcı kişi bilgilerini klavyeden girdikten sonra programı kapatıp dosya içerisine baktığımda sadece en son girilen kişi bilgilerini görüyorum. Yani kullanıcı ard arda giriş yaptığında en son kişiye ait olan bilgiler dosyaya yazılıyor. Programı "w" yazma modunda kullanıyorum ve bu problem dolayısıyla "w+" modunda da denedim ancak sonuç aynı. Yine sadece tek bir kişinin bilgileri dosyada saklanıyor. Kodları aşağıda paylaşıyorum. Saygılar


Kod:
#include <stdio.h>
#include <stdlib.h>     // "stdlib" library contains of exit() and malloc function
#include <Windows.h>   // "Windows" library contains of Sleep() function which waits the system as you want

struct personKnowledge
{
	char number[16];
	char name[16];
	char surname[16];
};

void newRecord();
void display();
void deletE();
void add();
void update();

FILE *ptrFILE;

int main()
{
	int choice;
	do
	{
		printf("\n\t\t *-* Phone Book Program *-*");
		printf("\n\n\t\t 1) New record");   // The options are being presented to user
		printf("\n\n\t\t 2) Display person knowledge");
		printf("\n\n\t\t 3) Delete someone");
		printf("\n\n\t\t 4) Add new person");
		printf("\n\n\t\t 5) Update person knowledge");
		printf("\n\n\t\t 6) Exit");
		printf("\n\n\nEnter your choice: ");
		scanf("%d", &choice);
		switch (choice)
		{
		case 1:
		{
			newRecord();
			break;
		}
		case 2:
		{
			break;
		}
		case 3:
		{
			break;
		}
		case 4:
		{
			break;
		}
		case 5:
		{
			break;
		}
		case 6:
		{
			printf("\nWorking has been completed.\n");
			exit(EXIT_SUCCESS);
			break;
		}
		default:
		{
			printf("\nWrong entry! The program has been terminated.\n");
		}
		}
	} while (choice >= 1 && choice <= 6);
	return 0;
}

void newRecord()
{
	system("cls");   // Screen is being cleaned
	if ((ptrFILE = fopen("Phone Book.txt", "w")) == NULL)
	{
		printf("The file couldn't open\n");
	}
	else
	{
		struct personKnowledge *p;   // p means person
		p = (struct personKnowledge *)malloc(sizeof(struct personKnowledge));   // Memory is being allocated
		fflush(stdin);
		printf("\n\nDetermine person name: ");   // User is entering the person's knowledge and they are being saved in file
		gets(p->name);
		printf("Determine %s's surname: ", p->name);
		gets(p->surname);
		printf("Determine %s's number: ", p->name);
		gets(p->number);
		fprintf(ptrFILE, "Name\t\t\t\tSurname\t\t\t\tNumber\n");
		fprintf(ptrFILE, "--------\t\t   ----------------\t\t------------------------\n");
		fprintf(ptrFILE, "\n%s%33s%38s\n", p->name, p->surname, p->number);
		free(p);
		printf("Please wait, information is saving to file..\n");
		Sleep(750);
		printf("*-* Saving operation has been completed. *-*");
	}
	fclose(ptrFILE);
}
 
Penqueen
Banned
düz bir metin belgesine kayıtları yapıyorsun
update komutuyla her seferinde mevcut satır yenisiyle değişiyor
her yeni kayıtta programa sonraki satırdan devam ettirmen gerekir
 
NoWeDoR
Cool Çırak
update komutu nedir hocam?

kod deyimlerinde void update(); fonksiyonu var ancak oda faal bile değil henüz.
 
Üst