✨ 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,25 +4,27 @@
|
||||
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
char line[255];
|
||||
int valid = 0;
|
||||
|
||||
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;
|
||||
char subject;
|
||||
char* password;
|
||||
char password[64];
|
||||
|
||||
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
||||
|
||||
|
||||
int occ = 0;
|
||||
for(int i=0; password[i] != 0; i++) {
|
||||
for(int i=0; password[i]; i++)
|
||||
if(password[i] == subject) occ++;
|
||||
}
|
||||
|
||||
|
||||
if(occ <= end && occ >= start) valid++;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -3,16 +3,20 @@
|
||||
|
||||
int main(void) {
|
||||
FILE *fp;
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
char line[255];
|
||||
int valid = 0;
|
||||
|
||||
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;
|
||||
char subject;
|
||||
char* password;
|
||||
char password[64];
|
||||
|
||||
sscanf(line, "%d-%d %c: %s\n", &start, &end, &subject, password);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user