Nietzsche says "God is dead" God says "Nietzsche is dead "
Header image

Phone Book – Telefon Defteri C++

Posted by ALonon in C++

C++ ile yazdığım bir telefon defteri programı,

Ubuntu’da yazıldığı için windows’altında çalıştırmak için dosya yolunu tam girmeniz gerekmekte ( c:\example.txt gibi)

Ayrıca strcmp char kontrolu yapmadığından, isim’i tek karakter girmeyin.

Bir kaydı silmek için temp dosyası kullandım. Silinicek kayıt hariç bütün kayıtlar temp’e kayıt edildikten sonra dosyanın adını değiştirdim.

Umarım işinize yarar.

It’s a phone book program written with c++

I wrore it in Ubuntu so to use it with Windows, you should change exact file path (c:\example)

Also strcmp function can not compare two chars, so do not write one char for name.

I used a temp file to delete a record. All records ( except deleted one) is saved in temp.txt. Then i changed temp.txt name.

#include 
#include 
#include 
#include 

using namespace std;

void add(char name[100],char surname[100], char phone[20]) {
	FILE *a;
	a = fopen("example.txt","a");
	fputs (name,a);
	fputs ("|",a);
	fputs (surname,a);
	fputs ("|",a);
	fputs (phone,a);
	fputs ("\n",a);
	fclose(a);

}

void list() {
	char t;
	FILE *a;
	a = fopen("example.txt","r");
	   while(!feof(a)) {
		   t=fgetc(a);
		   if(t != EOF && t != '|')
			   cout<>i;
		if(i == '1'){
			cout<<"name"<>name;
			cout<<"surname"<>surname;
			cout<<"phone"<>phone;
			add(name,surname,phone);
		}
		else if(i == '2'){
			cout<<"write name to delete"<>name;
			del(name);
		}
		else if(i == '3') {
			list();
		}
		else if(i == '4') {
			exit(0);
		}
		else {
			cout<<"wrong parameter"<

	

Related posts

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

Leave a Reply