Untitled diff

Created Diff never expires
8 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
50 lines
19 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
59 lines
#include <ctype.h>
#include <ctype.h>
#include <errno.h>
#include <errno.h>
#include <regex.h>
#include <regex.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <limits.h>
#include "main.h"
#define to_find "^[a-zA-Z0-9]+$"
int main(int argc, char * argv[])
int main(int argc, char * argv[])
{
{
int ret_val;
int ret_val;
regex_t regex;
regex_t regex;
FILE *fp;
FILE *fp;
char file[PATH_MAX];
char line[1024];
char line[1024];
if (regcomp(&regex, to_find, REG_EXTENDED) != 0)
if (regcomp(&regex, to_find, REG_EXTENDED) != 0)
{
{
fprintf(stderr, "Failed to compile regex '%s'\n", to_find);
fprintf(stderr, "Failed to compile regex '%s'\n", to_find);
return EXIT_FAILURE;
return EXIT_FAILURE;
}
}
if (argc > 2)
if (argc > 2)
{
{
printf("Usage: tree OR tree [filename]\n");
printf("Usage: tree OR tree [filename]\n");
return EXIT_FAILURE;
return EXIT_FAILURE;
}
}
else if (argc == 2)
else if (argc == 2)
{
{
fp = fopen(strcat(argv[1],".dat"), "r");
sprintf(file, "%s.dat", argv[1]);
fp = fopen(file, "r");
if( fp == NULL ) {
perror("Error");
return -1;
}
printf("file opened\n");
printf("file opened\n");
while ((fgets(line, 1024, fp)) != NULL)
while (fscanf(fp, "%1023s", line) > 0)
{
{
line[strlen(line) - 1] = '\0';
if ((ret_val = regexec(&regex, line, 0, NULL, 0)) != 0)
if ((ret_val = regexec(&regex, line, 0, NULL, 0)) != 0);
{
{
printf("Error: %s\n", line);
printf("Not match: %s\n", line);
return EXIT_FAILURE;
//return EXIT_FAILURE;
} else {
printf("Match: %s\n", line);
}
}
}
}
regfree(&regex);
fclose(fp);
fclose(fp);
printf("File closed\n");
printf("File closed\n");
}
}
return 0;
return 0;
}
}