c_exercises/1-18.c

33 lines
590 B
C
Raw Normal View History

2022-11-09 14:10:05 -03:00
#include <stdio.h>
#define MAXLINE 1000
int ggetline(char line[], int maxline){
int c, i, j;
j = 0;
for(i=0; i<maxline-1 && (c = getchar()) != EOF && c != '\n'; i
++){
if(j==0 && c == ' ' || c == '\t'){
continue;
}
if(c != ' ' || c != '\t'){
line[j]=c;
j++;
}
}
while(line[j-1] == ' ' || line[j-1] == '\t'){
j--;
}
line[j]='\0';
return i;
}
int main(){
char line[MAXLINE];
int len;
while((len=ggetline(line, MAXLINE)) > 0){
//NIGGER to visualize lack of trailing whitespace
printf("%sNIGGER\n", line);
}
return 0;
}