<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Open source blog, linux, php, python, security &#187; fput</title>
	<atom:link href="http://www.alonon.net/tag/fput/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alonon.net</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 07:23:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>

   <image>
    <title>Open source blog, linux, php, python, security</title>
    <url>http://0.gravatar.com/avatar/5152c5736f5f8dd9570ffb2f9068e8ab.png?s=48</url>
    <link>http://www.alonon.net</link>
   </image>
		<item>
		<title>Phone Book &#8211; Telefon Defteri C++</title>
		<link>http://www.alonon.net/phone-book-telefon-defteri-c/</link>
		<comments>http://www.alonon.net/phone-book-telefon-defteri-c/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 11:09:39 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[foef]]></category>
		<category><![CDATA[fput]]></category>
		<category><![CDATA[phone book]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=266</guid>
		<description><![CDATA[C++ ile yazdığım bir telefon defteri programı, Ubuntu&#8217;da yazıldığı için windows&#8217;altında çalıştırmak için dosya yolunu tam girmeniz gerekmekte ( c:\example.txt gibi) Ayrıca strcmp char kontrolu yapmadığından, isim&#8217;i tek karakter girmeyin. Bir kaydı silmek için temp dosyası kullandım. Silinicek kayıt hariç bütün kayıtlar temp&#8217;e kayıt edildikten sonra dosyanın adını değiştirdim. Umarım işinize yarar. It&#8217;s a phone &#8230; <a href="http://www.alonon.net/phone-book-telefon-defteri-c/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>C++ ile yazdığım bir telefon defteri programı,</p>
<p>Ubuntu&#8217;da yazıldığı için windows&#8217;altında çalıştırmak için dosya yolunu tam girmeniz gerekmekte ( c:\example.txt gibi)</p>
<p>Ayrıca strcmp char kontrolu yapmadığından, isim&#8217;i tek karakter girmeyin.</p>
<p>Bir kaydı silmek için temp dosyası kullandım. Silinicek kayıt hariç bütün kayıtlar temp&#8217;e kayıt edildikten sonra dosyanın adını değiştirdim. </p>
<p>Umarım işinize yarar.</p>
</p>
<p>It&#8217;s a phone book program written with c++</p>
<p>I wrore it in Ubuntu so to use it with Windows, you should change exact file path (c:\example)</p>
<p>Also strcmp function can not compare two chars,  so do not write one char for name.</p>
<p>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.</p>
<pre lang="c++">
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

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 &#038;&#038; t != '|')
			   cout<<t;
		   else if(t == '|')
			   cout<<"\t";

	   	}
	fclose(a);
}

void del(char name[100]) {
	FILE *temp;
	FILE *a;
	a = fopen("example.txt","r");
	char t[100],tempname[120];
	int i=0;
	bool buldu = false;
	for(int i=1;i<100;i++)
		t[i]=' ';
	temp = fopen("temp.txt","w+");
	 while (fgets(t, 222, a)) {
		 while(t[i] != '|') {
			 tempname[i]=t[i];
			 i++;
		 }
		 if(strcmp(tempname,name) != 0)
			 fputs(t,temp);
		 else
			 buldu = true;
		 i = 0;
	   }
	 if(buldu) {
	 rename("example.txt", "temp2.txt");
	 rename("temp.txt", "example.txt");
	 rename("temp2.txt", "temp.txt");
	 }
	 fclose(a);
	 fclose(temp);

}

int main () {

	char name[20],surname[100],phone[20];
	char i=0;

	while(i != '4') {
		cout<<"1. add"<<endl<<"2. delete"<<endl<<"3. list"<<endl<<"4 exit "<<endl; 		cin>>i;
		if(i == '1'){
			cout<<"name"<<endl; 			cin>>name;
			cout<<"surname"<<endl; 			cin>>surname;
			cout<<"phone"<<endl; 			cin>>phone;
			add(name,surname,phone);
		}
		else if(i == '2'){
			cout<<"write name to delete"<<endl; 			cin>>name;
			del(name);
		}
		else if(i == '3') {
			list();
		}
		else if(i == '4') {
			exit(0);
		}
		else {
			cout<<"wrong parameter"<<endl;
			i=0;
		}
	}

    return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/phone-book-telefon-defteri-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

