Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@impronunciable
Created October 2, 2011 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save impronunciable/1257799 to your computer and use it in GitHub Desktop.
Save impronunciable/1257799 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char *argv[]) {
int charcount = 0;
float timecount = 0; /* number of characters seen */
FILE *in_file; /* input file */
/* character or EOF flag from input */
float f1,f2;
int ch,l;
char linea[1000], extr[1000];
in_file = fopen(argv[2], "r");
if (in_file == NULL) {
printf("Cannot open %s\n", argv[2]);
exit(8);
}
while(fgets(linea, 1000, in_file) != NULL){
l = strlen(linea);
if(linea[l - 2] != '#'){
sscanf(linea,"%f %f %s",&f1,&f2,extr);
charcount += strlen(extr) - 1;
timecount += f2 - f1;
}
}
printf("charcount: %d\t timecount: %f\n",charcount,timecount);
fclose(in_file);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment