The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Average in awk saint2006 Shell Programming and Scripting 6 06-19-2008 03:09 PM
how to average in awk saint2006 Shell Programming and Scripting 4 06-04-2008 12:29 PM
calculate average of multiple line data smacherla HP-UX 4 05-23-2008 05:39 PM
Use awk to calculate average of column 3 grossgermany UNIX for Dummies Questions & Answers 6 07-27-2007 02:29 PM
calculate average of column 2 onthetopo UNIX for Dummies Questions & Answers 0 07-06-2007 09:16 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 11-12-2008
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
calculate average

I have a file which is
2
3
4
5
6
6

so i am writing program in C to calculate mean..

#include<stdio.h>
#include<string.h>
#include <math.h>
double CALL mean(int n , double x[])
main (int argc, char **argv)
{
char Buf[200],SEQ[100];
int i;
double result = 0;
FILE *fp;
fp=fopen(argv[1],"r");
while(fgets(Buf,20,fp))
{
sscanf(Buf,"%s",SEQ);
x=SEQ;
//printf("%s\n",SEQ);
}
fclose(fp);
{
for (i = 0; i < n; i++) result += x[i];
result /= n;
return result;
printf("%f", result);
}
}


But it is showing segmentation fault
any solution?
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0