I'm working on a C program that takes in an input of lines of text, and return it by printing only 40 characters each. So far, I have this code:
#include <stdio.h>
#include <stdlib.h>
int main() {
char input = getchar();
int numChar;
int total;
while ((input != EOF) && (input != '\n')) {
++numChar;
if (numChar > 40) {
printf("\n");
++total;
numChar = 0;
}
putchar(input);
input = getchar();
}
return EXIT_SUCCESS;
}
Just updated my post with a new draft I have. For this attempt I am trying to print each character as it takes each input but if the character count is over 40, to make a new line. But, I don't get an output as expected.
I'm not sure if thats whats you're asking. Basically every 40 characters, a
newlinecharacter is printed.Edit:
Your code seem to work fine if you were to initiliaze
numChar-->numChar = 0andtotal-->total = 0.