I’m the beginner to write the C program. Always got the error on output. Anyone can help. The program is open and read the text file. Then count all the number occurrence.
File format like this
21 43 32
32 32 21
43 5 6…
The code as below
Code:#include <stdio.h> #include <stdlib.h> #define SIZE 0 int main () { int number1[SIZE], number2[SIZE]; int i, j; int count; int n; char filename[40] ; FILE *fp; printf("Enter file name: "); gets( filename ); fp = fopen( filename, "r" ); if ( fp == NULL ) { printf("Cannot open %s for reading \n", filename ); exit(1); /* terminate program */ } n = fgetc( fp ) ; while ( n != EOF ) { for (i=0; i<n; i++) { count=0; for (j=0; j<n; j++) { if (number1[j] == number1[i]) { count++; } } number2[i] = count; } printf ("\n\n"); for (i=0; i<n; i++) { printf ("Number %d: occurance %d times(s)\n", number1[i], number2[i]); } fclose( fp ); return 0; } }



1Likes
LinkBack URL
About LinkBacks


