Exercise 1-22 in the K&R. What error is responsible?
by Arct1c_f0x from LinuxQuestions.org on (#57TEV)
Code:// This program is specified by Exercise 1-22 of the K&R Ansi edition
/* Exercise 1-22. Write a program to ``fold'' long input lines into two or more shorter lines after
the last non-blank character that occurs before the n-th column of input. Make sure your
program does something intelligent with very long lines, and if there are no blanks or tabs
before the specified column. */
#include <stdio.h>
#define MAXINPUTLINELEN 80
int c, i;
char CurrenInputLine[500];
int main() {
i = 0;
while ((c = getchar() != EOF) || ((c=getchar()) != '\n')) {
CurrenInputLine[i] = c;
if (i % MAXINPUTLINELEN == 0) {
if (CurrenInputLine[i] == ' ' || CurrenInputLine[i] == '\t') {
++i;
CurrenInputLine[i] = '\n';}
else if (CurrenInputLine[i] != ' ' || CurrenInputLine[i] == '\t') {
while ((c = getchar()) != EOF) {
if (c != ' ' || c != '\t') {
CurrenInputLine[i] = c;
++i;}
else if (c == ' ' || c == '\t') {
CurrenInputLine[i] = c;
++i;
CurrenInputLine[i] = '\n';
break;
}
}
}
}
++i;
}
++i;
CurrenInputLine[i] = '\0';
printf("%s", CurrenInputLine);
}
in std output it says: "Segmentation fault (core dumped)" which I understand has to do with the program's access to the memory that it's creating. What am I doing wrong?
My humble gratitude,


/* Exercise 1-22. Write a program to ``fold'' long input lines into two or more shorter lines after
the last non-blank character that occurs before the n-th column of input. Make sure your
program does something intelligent with very long lines, and if there are no blanks or tabs
before the specified column. */
#include <stdio.h>
#define MAXINPUTLINELEN 80
int c, i;
char CurrenInputLine[500];
int main() {
i = 0;
while ((c = getchar() != EOF) || ((c=getchar()) != '\n')) {
CurrenInputLine[i] = c;
if (i % MAXINPUTLINELEN == 0) {
if (CurrenInputLine[i] == ' ' || CurrenInputLine[i] == '\t') {
++i;
CurrenInputLine[i] = '\n';}
else if (CurrenInputLine[i] != ' ' || CurrenInputLine[i] == '\t') {
while ((c = getchar()) != EOF) {
if (c != ' ' || c != '\t') {
CurrenInputLine[i] = c;
++i;}
else if (c == ' ' || c == '\t') {
CurrenInputLine[i] = c;
++i;
CurrenInputLine[i] = '\n';
break;
}
}
}
}
++i;
}
++i;
CurrenInputLine[i] = '\0';
printf("%s", CurrenInputLine);
}
in std output it says: "Segmentation fault (core dumped)" which I understand has to do with the program's access to the memory that it's creating. What am I doing wrong?
My humble gratitude,