Created
January 16, 2018 11:32
-
-
Save makunomark/0157078010185a2b3092258bb5c9f9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
int num_string = 0; | |
int num_char = 0; | |
%} | |
string [^\n\t ]+ | |
%% | |
{string} {++num_string; num_char+=yyleng;} | |
%% | |
int main(int argc, char *argv[]){ | |
struct stat st; | |
yyin = fopen(argv[1], "r"); | |
stat(argv[1], &st); | |
yylex(); | |
printf("Number of strings: %d\n", num_string); | |
printf("Number of characters: %d\n", num_char); | |
printf("File size: %d bytes\n", st.st_size); | |
fclose(yyin); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment