(C) day 5 wip
This commit is contained in:
parent
a54f6d3dc5
commit
03584720ac
40
05/day5.c
40
05/day5.c
|
@ -1,33 +1,49 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ArrayWithLength {
|
||||
int length;
|
||||
char* content;
|
||||
};
|
||||
#include <sys/stat.h>
|
||||
|
||||
int isSameLetter(char a, char b) {
|
||||
char diff = (a > b) ? a - b : b - a;
|
||||
return diff == 32;
|
||||
}
|
||||
|
||||
struct ArrayWithLength processArray(char* input, int length) {
|
||||
char output [length];
|
||||
int processArray(char* input, int length) {
|
||||
int outputLength = 0;
|
||||
for (int i=0; i<length-1; i++) {
|
||||
if (isSameLetter(input[i], input[i+1]) == 1) {
|
||||
printf("reacting: %c%c\n", input[i], input[i+1]);
|
||||
i++;
|
||||
} else {
|
||||
output[outputLength] = input[i];
|
||||
input[outputLength] = input[i];
|
||||
outputLength++;
|
||||
}
|
||||
}
|
||||
struct ArrayWithLength ret;
|
||||
ret.length = outputLength;
|
||||
ret.content = output;
|
||||
return ret;
|
||||
return outputLength + 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct stat stbuffer;
|
||||
FILE *inputFile = fopen("input", "r");
|
||||
fstat(fileno(inputFile), &stbuffer) != -1;
|
||||
int inSize = stbuffer.st_size;
|
||||
//inSize = 40;
|
||||
char *input = malloc(inSize);
|
||||
fgets(input, inSize, inputFile);
|
||||
|
||||
int lastLength = inSize;
|
||||
|
||||
printf("%s\n", input);
|
||||
int outLength = inSize;
|
||||
do {
|
||||
lastLength = outLength;
|
||||
outLength = processArray(input, lastLength);
|
||||
printf("%s\n", input);
|
||||
printf("%d\n", outLength);
|
||||
} while (lastLength != outLength);
|
||||
|
||||
printf("%d\n", outLength);
|
||||
|
||||
fclose(inputFile);
|
||||
free(input);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user