Last active
February 2, 2024 16:54
-
-
Save emsesc/d8e88e6828a3358afde75a5c17d10d22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
// initialize input array and int array holding offending lines | |
char lines[1000]; | |
int offend[100] = {0}; | |
// initialize counter for number of offending lines and the current lineNum | |
int oLines = 0; | |
int lineNum = 0; | |
// continuously receive lines of input until Null | |
while (fgets(lines, sizeof(lines), stdin) != NULL) { | |
// loop through chars in line | |
for (int i = 0; lines[i] != '\0'; i ++) { | |
// printf("Counter: %d, oLines: %d\n", i, oLines); | |
// if counter is at 51, 101, etc. newline prints | |
// will not print newline twice if the 51st char is a newline | |
if (i > 0 && i % 50 == 0 && lines[i] != '\n') { | |
printf("\n%c", lines[i]); | |
// special case: count line as offending | |
if (i == 50) { | |
offend[oLines] = lineNum; | |
oLines ++; | |
} | |
} else { | |
printf("%c", lines[i]); | |
} | |
} | |
lineNum ++; | |
} | |
printf("\nTotal lines over 50 chars: %d\n", oLines); | |
printf("Offending lines: "); | |
for (int i = 0; i < oLines; i ++) { | |
printf("%d, ", offend[i]); | |
} | |
printf("%c", '\n'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment