biri seçmek derken yanlış belirtmişim.1 e basım enterlıyorum.yani karakter okutmadım (int)..kayit() fonksiyonunda fgets kullanımındaki hatamı göremedim..
bu arada deneme yanilma şöyle bir okuma kodu yazdım.
Kod:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
FILE *dosya;
char s[100000];
int i;
int main()
{
dosya=fopen("denedik.txt","r");
while(fscanf(dosya,"%s\n",s)!=EOF)printf("%s",s);
getch();
fclose(dosya);
}
** okumada kelimeleri bitisik okuyor.printf de "%s" araya bir bosluk( ' ' ) koydum bu sefer normal okudu.sakıncası olurmu algoritma açısından ?
PHP Kodu:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
char s[100000];
FILE *dosya;
char secim;
void kayit();
int oku();
//char *fgets();
int main()
{
system ("cls");
printf ("\n ----------------------------------");
printf ("\n | KAYIT PROGRAMI |");
printf ("\n | ELEKTRiK-ELEKTRONiK |");
printf ("\n | MUHENDiSLiGi |");
printf ("\n ----------------------------------");
printf ("\n | SUBAT - 2010 |");
printf ("\n ----------------------------------");
printf ("\n\n\n\n **********");
printf ("\n * DENEME *");
printf ("\n **********");
printf ("\n\n\n\n\n Cemal");
printf ("\n ");
printf ("\n ");
printf ("\n\n\n ____Herhangi Bir Tusa Basiniz___");
secim=getch();
system("cls");
printf("____Ne yapmak istiyorsunuz ____\n\n");printf("1_| Kayit \n2_| Okuma\n3_| CIKIS\n");
scanf("%d",&secim);
if(secim==1){
printf("Simdi kaydetmek istediklerinizi girebilirsiniz\n\n");
kayit();
}
if(secim==2){
printf("*****************\n ");
oku();
}
}
void kayit()
{
int i;
dosya=fopen("denedik.txt","w");
printf("Ne yazmak istiyorsan gir > ");
for(i=0;i<5;i++){
gets(s);
fprintf(dosya,"%s\n",s);}
getch();
fclose(dosya);
}
int oku()
{
dosya=fopen("denedik.txt","r");
while(fscanf(dosya,"%s",s)!=EOF){
printf("%s ",s);}
getch();
fclose(dosya);
}
en son hali programin..kayit da yapıyor okuma da..ancak fgets kullanamadim.
kayit(); fonksiyonunda okuyacağı satır 5 belli.ben böyle olsun istemiyorum..istedğim bir an kayıt fonksiyonundan çıkmak ve dosyaya kaydettirmek istiyordum...
Bookmarks