✨ Updated to use fgets
This commit is contained in:
parent
1d4ec295f7
commit
9ff8098f52
BIN
2020/2/parse
BIN
2020/2/parse
Binary file not shown.
@ -4,24 +4,26 @@
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char* line = NULL;
|
char line[255];
|
||||||
size_t len = 0;
|
|
||||||
int valid = 0;
|
int valid = 0;
|
||||||
|
|
||||||
fp = fopen("input", "r");
|
fp = fopen("input", "r");
|
||||||
|
|
||||||
while(getline(&line, &len, fp) != -1) {
|
if(fp == NULL) {
|
||||||
|
perror("Error opening file.");
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(fgets(line, sizeof(line), fp) != NULL) {
|
||||||
int start, end;
|
int start, end;
|
||||||
char subject;
|
char subject;
|
||||||
char* password;
|
char password[64];
|
||||||
|
|
||||||
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
||||||
|
|
||||||
|
|
||||||
int occ = 0;
|
int occ = 0;
|
||||||
for(int i=0; password[i] != 0; i++) {
|
for(int i=0; password[i]; i++)
|
||||||
if(password[i] == subject) occ++;
|
if(password[i] == subject) occ++;
|
||||||
}
|
|
||||||
|
|
||||||
if(occ <= end && occ >= start) valid++;
|
if(occ <= end && occ >= start) valid++;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -3,16 +3,20 @@
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char* line = NULL;
|
char line[255];
|
||||||
size_t len = 0;
|
|
||||||
int valid = 0;
|
int valid = 0;
|
||||||
|
|
||||||
fp = fopen("input", "r");
|
fp = fopen("input", "r");
|
||||||
|
|
||||||
while(getline(&line, &len, fp) != -1) {
|
if(fp == NULL) {
|
||||||
|
perror("Error opening file.");
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(fgets(line, sizeof(line), fp) != NULL) {
|
||||||
int start, end;
|
int start, end;
|
||||||
char subject;
|
char subject;
|
||||||
char* password;
|
char password[64];
|
||||||
|
|
||||||
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user