Skip to content

Instantly share code, notes, and snippets.

@Learath2
Last active August 29, 2015 14:04
Show Gist options
  • Save Learath2/5ee704b4b867d459fc00 to your computer and use it in GitHub Desktop.
Save Learath2/5ee704b4b867d459fc00 to your computer and use it in GitHub Desktop.
K&R2 Exercise 1-20
#include <stdio.h>
#define TABSTOP 8
int mod(float, float);
int main()
{
int c, i, cc;
cc = 0;
while((c = getchar()) != EOF){
if(c != '\t'){
if(c == '\n')
cc = -1;
putchar(c);
++cc;
}
else{
do
putchar(' ');
while(mod(++cc, TABSTOP) != 0);
}
}
}
int mod(float dividend, float divisor)
{
int division;
division = dividend/divisor;
return dividend - (division * divisor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment