Article 57TEV Exercise 1-22 in the K&R. What error is responsible?

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,latest?d=yIl2AUoC8zA latest?i=QYyoY7iUo4M:sVm_iPB7VRA:F7zBnMy latest?i=QYyoY7iUo4M:sVm_iPB7VRA:V_sGLiP latest?d=qj6IDK7rITs latest?i=QYyoY7iUo4M:sVm_iPB7VRA:gIN9vFwQYyoY7iUo4M
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments