Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created March 17, 2015 10:46
Show Gist options
  • Select an option

  • Save tomcha/ed3856a0bfa6e84f8e13 to your computer and use it in GitHub Desktop.

Select an option

Save tomcha/ed3856a0bfa6e84f8e13 to your computer and use it in GitHub Desktop.
1-18
#include <stdio.h>
#define MAXCHAR 100
void delblank(char line[], char newline[]);
void cleararray(char array[]);
int main(){
int c;
int i;
char line[MAXCHAR];
char newline[MAXCHAR];
while((c = getchar()) != EOF){
line[i] = c;
if(c == '\n'){
delblank(line, newline);
printf("%s\n", newline);
i = 0;
cleararray(line);
cleararray(newline);
}else{
i++;
}
}
}
void delblank(char line[], char newline[]){
int i, j;
j = 0;
for(i = 0; line[i] != '\n'; i++){
if(line[i] == ' ' || line[i] == '\t'){
i++;
}else{
newline[j] = line[i];
j++;
}
}
}
void cleararray(char array[]){
int i;
for(i = 0; i < MAXCHAR; i++){
array[i] = '\0';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment