Last active
March 27, 2017 20:08
-
-
Save keremistan/38af6ded6bb9f3d6c976ec9fd9b66970 to your computer and use it in GitHub Desktop.
Bu dosyanın ana teması (adından da anlaşılacağı üzere) fget() ve fput() fonksiyonları. Bu fonksiyonların 'absolute path' ile nasıl kullanıldığını gözlemleyebiliriz!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void yazma(); | |
void okuma(); | |
int main(void){ | |
/* w = yazmak icin olusturuyor // write | |
* r = okumak icin aciyor // r = read | |
* a = dosyanin sonuna ekleyerekten yazmak icin aciyor | |
* r+ = dosyayi okumak ve yazmak icin aciyor | |
* w+ = yazmak icin olusturuyor, eger daha onceden ayni isimle varsa, siliniyor | |
* a+ = dosya okunmak ve yazilmak icin aciliyor, yoksa olusturuluyor | |
* */ | |
// fgetc - fputc | |
yazma(); | |
okuma(); | |
return 0; | |
} | |
void yazma(){ | |
FILE *fp = fopen("/Users/keremdede/Desktop/ornek.txt", "w"); | |
if(fp == NULL){ | |
printf("Stream acilamadi\n"); | |
return; | |
} | |
const char *mesaj = "Matematik (aslinda) cok zevkli bir derstir!"; | |
size_t uzunluk = strlen(mesaj); | |
int i = 0; | |
while(i < uzunluk){ | |
fputc(mesaj[i], fp); | |
i++; | |
} | |
fclose(fp); | |
} | |
void okuma(){ | |
FILE *fr = fopen("/Users/keremdede/Desktop/ornek.txt", "r"); | |
if(fr == NULL){ | |
printf("Stream acilamadi!\n"); | |
return; | |
} | |
int c = 0; | |
while ( (c = fgetc(fr)) != EOF ){ // End Of File = Dosya Sonu | |
putchar(c); | |
} | |
fclose(fr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment