View Single Post
Old 11-28-2004, 10:05 PM   #1 (permalink)
ej25
Registered User
 
Join Date: Nov 2004
Posts: 1
ej25 is on a distinguished road
what's wrong with this code?????

Code:
#include <stdio.h> 
#include <stdlib.h>
#include <fcntl.h>             /* defines options flags */ 
#include <sys/types.h>     /* defines types used by sys/stat.h */ 
#include <sys/stat.h>        /* defines S_IREAD & S_IWRITE  */ 

int main( )
{
  FILE *fd;
  int fd2;
  int sec,quize; 
  char buffer[1024];
  char buffer2[1024];
  int a,b,n,c=0;
  int random[100][100];

 
  int i,Sum1,Sum2,ii;
  float aver1,aver2;
  int j;
  fd = fopen("input.txt","w+");
   
  printf("Enter number of sections:");
  scanf("%d",&sec);

  printf("Enter number of quizes in each section:");
  scanf("%d",&quize);
  c= sec*quize;

  random[c][10];

  for(a=0;a<c;a++){
    for(b=0;b<10;b++)
       random[a][b]=rand()%21;
  }
 
  for(b=0;b<10;b++){
    for(a=0;a<c;a++){
      fprintf(fd,"%d",random[a][b]);
      fprintf(fd,"\t");
    }
    fprintf(fd,"\n");
  }

  for(a=0;a<c;a++){
    for(b=0;b<10;b++)
      printf("random[%d][%d]=%d\n",a,b,random[a][b]);
  }
	
  fclose (fd);  
        
  fd = fopen("input.txt","r+");
  i=1;
  ii=0; 
  Sum1=0; 
  Sum2=0;
  j=0;
  for(j=0;j!=c;j++){
    printf("section number %d\n",j);
    while(ii!=10){
      fscanf(fd,"%d",&a);
      printf("a:%d\n",a);
      Sum1=Sum1+a;
      i=1;
      while(i!=c){
         fscanf(fd,"%d",&a);
         i++;
      }
      ii++;
    }
    printf("%d\n",Sum1);
    aver1 = Sum1 / (float) ii;
    printf("%f\n",aver1);
  }
  fclose(fd);   
  return (0);
}

Last edited by redhead; 11-28-2004 at 11:45 PM. Reason: Learn to use [ code] tags...
ej25 is offline   Reply With Quote