0

Excercise Question AINSI C Book

Excercise: Write a program to remove trailing blanks and tabs from each line of input and deletes entirely blank lines. Edit: I've corrected it and you can check it out in the answers or the codeplayground. The program I've written does give error. That's the reason why I'd like to get some help. I do not request from you to rewrite this program or correct it entirely. I want to get some feedback for the reason it gives error, the feedback on errors of my logic and maybe some insight to guide me to write better code and thus completing the excercise. I've tried to make my code readable but I don't know to what extent I have achieved that. Thanks in advance. For whom needs to see on the code playground: https://code.sololearn.com/cPjces6OXrJB/#c #include <stdio.h> void deletingfunction(char inputs[i], int i); /* the program removes trailing blanks and tabs from each line of input */ main() { char inputs[1000]; /* the string which will be the output at last */ int c; int i = 0; while (( c = getchar()) != EOF) { inputs[i] = c; if ( c == '\0') /* the aim of this part: when the end of a string is reached delete all the trailing blanks and tabs before the \n thus the trailing blanks */ { deletingfunction(inputs[i], i); } ++i; } printf("%s", inputs); } void deletingfunction(char inputs[i], int i) { i = i - 2; while( inputs[i] == ' ' || inputs[i] == '\t') { inputs[i] = '\b'; --i; } }

2nd Feb 2020, 10:20 AM
mert aydın
0 odpowiedzi