Created
March 12, 2015 07:34
-
-
Save huseyin/5734532af595b7e770bc to your computer and use it in GitHub Desktop.
Kernighan Çalışma Soruları [Soru-1]
This file contains hidden or 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
// C dili çalışmaları: Kernighan Soru-1 | |
#include <stdio.h> | |
int main(void) { | |
int j = 0, sekme = 5; | |
int i, kr, bosluk; | |
for ( ; ; ) { | |
kr = getchar(); | |
if (kr == '\t') { | |
// "\t" dememizin nedeni sekmeleri kontrol etmektir. | |
bosluk = sekme - j % sekme; | |
for (i = 0; i < bosluk; i++) | |
putchar(' '); | |
j += bosluk; | |
} | |
else if (kr == EOF) { | |
// Eğer dosya sonuysa programı kapat. | |
printf("Programdan cikildi!\n"); | |
} | |
else { | |
putchar(kr); | |
j += 1; | |
if (kr == '\n') | |
j = 0; | |
// "\n" dememizin nedeni ise satır sonunu kontrol etmektir. | |
// "j"'yi sıfırlamanın nedeni yukarıda tekrar kullanabilmektir. | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment