/* standard includes section */ #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <assert.h> /* make int64_t mean a 64 bit int on gcc and microsoft */ #ifdef _MSC_VER typedef __int64 int64_t; #else typedef long long int64_t; #endif /* change to reflect root name of the problem */ #define PROBLEM "count" #define MAX_FILE_LENGTH 200 #define MAX_LINE_LENGTH 1024 char infile[MAX_FILE_LENGTH]; FILE *in=0; char outfile[MAX_FILE_LENGTH]; FILE *out=0; void solve_problem(); int main(int argc, char *argv[]) { sprintf(infile, "%s.in", PROBLEM); sprintf(outfile, "%s.out", PROBLEM); in = fopen(infile, "r"); if (in == 0) { printf("could not open input file %s\n", infile); } out = fopen(outfile,"w"); if (out == 0) { printf("could not open output file %s\n", outfile); } if (in == 0 || out == 0) { exit(1); } solve_problem(); fclose(in); fclose(out); return 0; } /* this is the real work: the input and output files are opened, and you must solve the problem. This version merely reads in lines from the input file, prints them back out on the output file, followed by the total number of lines processed. */ void solve_problem() { int count=0; char line[MAX_LINE_LENGTH]; while (fgets(line,MAX_LINE_LENGTH,in)!=0) { ++count; } fprintf(out,"%d\n",count); }