2025-09-17 20:54:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#define maxInputSize 32000
|
|
|
|
|
#define maxOutputSize 32100
|
|
|
|
|
|
|
|
|
|
char buffer[maxInputSize] = { 0 };
|
|
|
|
|
|
|
|
|
|
void store(char to[]); // Complete
|
2025-09-19 00:00:30 +00:00
|
|
|
void enumerate(char data[]); // Complete, pending testing.
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
store(buffer);
|
|
|
|
|
enumerate(buffer);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-09-17 20:54:19 +00:00
|
|
|
|
|
|
|
|
//Status: Complete & Tested
|
|
|
|
|
void store(char to[]){
|
|
|
|
|
int toCrsr = 0;
|
|
|
|
|
for(int i = getchar();i != EOF; ++toCrsr){
|
|
|
|
|
to[toCrsr] = i;
|
|
|
|
|
i = getchar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Status: Complete, pending testing. Not testable until replicate is complete.
|
2025-09-19 00:00:30 +00:00
|
|
|
void enumerate(char data[]){
|
2025-09-17 20:54:19 +00:00
|
|
|
|
|
|
|
|
int dataCrsr = 0; // Stores currently accessed position in data[]
|
2025-09-19 00:00:30 +00:00
|
|
|
int wscursor = 0; //Stores the cursor position in ekorkingStorage
|
2025-09-17 20:54:19 +00:00
|
|
|
int lineLen = 0; // Stores the length of the current line being enumerated.
|
|
|
|
|
char workingStorage[maxOutputSize] = { 0 }; // Stores processed data until
|
|
|
|
|
// replicated to output.
|
|
|
|
|
|
|
|
|
|
//Begin main enumeration loop.
|
|
|
|
|
for(int current = data[dataCrsr]; current != 0;){
|
|
|
|
|
//Begin case: newline encountered with acceptable line length.
|
|
|
|
|
if(current == '\n' && lineLen >= 80){
|
|
|
|
|
//Reset line length in preparation for next dataset.
|
|
|
|
|
lineLen = 0;
|
2025-09-19 00:00:30 +00:00
|
|
|
// Increment wscursor and add a null ek yte at the end of valid data
|
|
|
|
|
// for replicate to break on.
|
2025-09-17 20:54:19 +00:00
|
|
|
++wscursor;
|
|
|
|
|
workingStorage[wscursor] = 0;
|
2025-09-19 00:00:30 +00:00
|
|
|
// Print line to stdout
|
|
|
|
|
for(wscursor = 0; workingStorage[wscursor] != 0;++wscursor){
|
|
|
|
|
putchar(workingStorage[wscursor]);
|
|
|
|
|
}
|
|
|
|
|
putchar('\n');
|
|
|
|
|
// Reset wscursor
|
2025-09-17 20:54:19 +00:00
|
|
|
wscursor = 0;
|
2025-09-19 00:00:30 +00:00
|
|
|
// Begin case: newline with unacceptable line length.
|
2025-09-17 20:54:19 +00:00
|
|
|
} else if (current == '\n' && lineLen < 80){
|
|
|
|
|
//Reset line length and wscuror in preparation for nxet dataset.
|
|
|
|
|
lineLen = 0;
|
|
|
|
|
wscursor = 0;
|
2025-09-19 00:00:30 +00:00
|
|
|
// Begin case: non-newline character.
|
2025-09-17 20:54:19 +00:00
|
|
|
}else if(current != '\n'){
|
2025-09-19 00:00:30 +00:00
|
|
|
// Increment line length, write to workingStorage at wscursor, and
|
|
|
|
|
// increment wscursor.
|
2025-09-17 20:54:19 +00:00
|
|
|
++lineLen;
|
|
|
|
|
workingStorage[wscursor] = current;
|
|
|
|
|
++wscursor;
|
|
|
|
|
}
|
|
|
|
|
//Regardless of result, fetch new data.
|
|
|
|
|
++dataCrsr;
|
|
|
|
|
current = data[dataCrsr];
|
|
|
|
|
}
|
|
|
|
|
}
|