ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/frameCount/src/frameCount.c
Revision: 36
Committed: Fri Jul 19 00:48:45 2002 UTC (21 years, 11 months ago) by mmeineke
Content type: text/plain
File size: 1112 byte(s)
Log Message:
moved the actual routine into a seperate source from the main. This allows the routine to
be used in other applications.

File Contents

# Content
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include "frameCount.h"
5
6
7 int frameCount( char* in_name ){
8
9 FILE *in_file;
10 int nFrames = 0;
11 int i, j, k;
12 int lineNum = 0;
13 char readBuffer[2000];
14
15 in_file = fopen( in_name, "r" );
16 if( in_file == NULL ){
17 printf( "Error opening \"%s\"\n", in_name );
18 exit(8);
19 }
20
21 if( feof( in_file ) ){
22 printf( "File ended unexpectedly at line %d\n", lineNum );
23 exit(8);
24 }
25
26 fgets( readBuffer, sizeof( readBuffer ), in_file );
27 lineNum++;
28
29 while( !feof( in_file ) ){
30
31 i = atoi(readBuffer);
32
33 if( feof( in_file ) ){
34 printf( "File ended unexpectedly at line %d, in frame%d\n", lineNum, nFrames+1 );
35 exit(8);
36 }
37 fgets( readBuffer, sizeof( readBuffer ), in_file );
38 lineNum++;
39
40 for(j=0; j<i; j++){
41
42 if( feof( in_file ) ){
43 printf( "File ended unexpectedly at line %d, with atom %d, in frame %d\n",
44 lineNum, j, nFrames+1 );
45 exit(8);
46 }
47 fgets( readBuffer, sizeof( readBuffer ), in_file );
48 lineNum++;
49 }
50
51 nFrames++;
52
53 fgets( readBuffer, sizeof( readBuffer ), in_file );
54 lineNum++;
55 }
56
57 fclose( in_file );
58
59 return nFrames;
60 }