Skip to content

Instantly share code, notes, and snippets.

@huseyin
Created March 12, 2015 07:34
Show Gist options
  • Save huseyin/5734532af595b7e770bc to your computer and use it in GitHub Desktop.
Save huseyin/5734532af595b7e770bc to your computer and use it in GitHub Desktop.
Kernighan Çalışma Soruları [Soru-1]
// 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