Hello all...sooo I managed to solve most of the program. This program is suppose to filter out all blank and tabs of the lines I type in, and completely delete all blank lines. However I am unsure of how to do this. It still seems like it is printing the blank line. It does however filter all spaces and tabs. I commented my code as necessary. Help much apprecated!
Code:
#include <stdio.h>
#define UNLIMITED 10000
void blanklessCopy(char to[], char from[]);
int getline(char line[]);
//prints lines without blanks or tabs
//delete lines that are completely blank
main(){
int len; //current line length
char line[UNLIMITED]; //current input line
char newLine[UNLIMITED]; //the new line
//while len is greater than 0
//means there was a line
while ((len = getline(line)) > 0){
//copy the line to newLine
blanklessCopy(newLine, line);
//what to do here?
//means it was a blank
if(newLine[0] == '\0'){
;
}
//otherwise just print the new
//filtered line
else{
printf("%s", newLine);
}
}
}
//copy from into to: assume to is big enough
//removes all blanks and tabs
void blanklessCopy(char to[], char from[]){
int i, i2;
i = i2 = 0;
while (from[i] != '\0'){
if (from[i] == '\t' || from[i] == ' '){
i++;
}
else {
to[i2] = from[i];
++i;
++i2;
}
}
to[i2] = '\0';
}
//read a line into s, return length
int getline(char s[]){
int c, i;
for(i = 0; (c = getchar()) != EOF && c != '\n'; ++i)
s[i] = c;
if(c == '\n'){
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}