Thread: file management in c help

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    file management in c help

    i try to solve one question to find out the mean, s.d using the file management. even they got no error but when compile it turns out random number so there is logic error but could u point out if i got any mistake. im bad in this chapter though
    this is my coding done so far,
    Code:
    #include<stdio.h>#include<math.h>
    
    
    main()
    {
    	FILE*real;
    	int i,j;
    	float x,s,sd,mean,sum,dev;
    	sum=0, s=0;
    	printf("please enter the number of data entered\n");
    	scanf("%d", &j);
    	
    	real=fopen("DATA","w");
    	for (i=1; i<=j; i++)
    	{
    		fscanf(real," %f", &x);
    		fprintf(real," %f", x);
    	}
    	fclose(real);
    	fprintf(real,"\n\n");
    	real=fopen("DATA","w");
    	for (i=1; i<=j; i++)
    	{
    		sum = sum + x;
    		printf("sum = %f", sum);
    		mean= sum/j;
    		printf("mean = %f", mean);
    		dev= x - mean;
    		printf("dev = %f", dev);
    		s = s + pow(dev,2);
    		sd = sqrt((s/j));
    		printf("sd = %f", sd);
    	}
    	fclose(real);
    }

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    26
    C File I/O Tutorial - Cprogramming.com

    Read this. You're opening the file in write mode in both instances.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file management in c
    By Animesh Gaitond in forum C Programming
    Replies: 4
    Last Post: 09-20-2011, 10:28 AM
  2. File Management in C
    By Figen in forum C Programming
    Replies: 6
    Last Post: 01-31-2011, 03:14 PM
  3. need help for file management
    By edesign in forum C Programming
    Replies: 5
    Last Post: 02-08-2008, 11:29 PM
  4. File Management :: Win32
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 12-13-2002, 05:35 PM