473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How did i get "Run-Time Check Failure #3 - The variable 'arr' is being used without b

This is for a homework but i'm stuck trying to figure out my error.


Expand|Select|Wrap|Line Numbers
  1. #include<stdlib.h>
  2. #include<math.h>
  3.  
  4. int getData(FILE *input, float *arr, float *mean, float *sD);
  5. float **pointing(float *arr, int n);
  6. void sortSelect(float **ptrArr, int n);
  7. void output(float *arr, float **ptrArr, float mean, float sD, int n);
  8.  
  9. int main(void)
  10. {
  11.     FILE *input;
  12.     int n;
  13.     float *arr; 
  14.     float mean; float sD;
  15.     float **ptrArr;
  16.  
  17.     n = getData(input, arr, &mean, &sD);//read in data using memory allocation and calculate sD
  18.     //ptrArr = pointing(arr, n);//pointers pointing to actual data
  19.     //sortSelect(ptrArr, n);
  20.     //output(arr, ptrArr, average, sD, n);
  21.  
  22.     return 0;
  23. }
  24.  
  25. int getData(FILE *input, float *arr, float *mean, float *sD)
  26. {
  27.     int n; int i = 0;
  28.     FILE *print;
  29.  
  30.     if ((input = fopen("Lab4.txt", "r"))== NULL )//check lab4.txt
  31.     {printf("ERROR!. \n"); system("pause"); exit(100);}
  32.  
  33.     fscanf(input, "Lab4.txt", &n);    //input number of data readings 
  34.  
  35.     arr = (float*) calloc(n, sizeof(float));//allocate memory for arr
  36.     if (*arr == NULL)    //check for NULL in pointer
  37.     {
  38.          printf("Memrory Overflow");
  39.          system("pause");
  40.          exit(100);
  41.     }
  42.  
  43.     //read in data and calculating average
  44.     while(fscanf(input, "%f", *(arr + i))!= EOF)
  45.         { *mean += *(arr + i);i++; }
  46.     *mean /= n;        
  47.  
  48.     //calculate standard deviation
  49.     for(i = 0; i<n; i++)
  50.         { *sD += pow(*(arr+i) + *mean, 2); }
  51.     *sD = sqrt(*sD * (1/n));
  52.  
  53.     //testing read in data 
  54.     if(!(print = fopen("Lab4_Output.txt", "w" )))
  55.     {printf("Can't open the txt file\n"); system("pause"); exit(100);}
  56.  
  57.     fprintf(print,"%d", n);
  58.  
  59.     for(int r=0; r < n; r++)
  60.     {
  61.         fprintf(print, "%3.1f", *(arr + r));
  62.     }
  63.     fclose(input);
  64.     return n;
  65. }
Data File
54
164.3 201.6 226.7 63.4 71.2 210.2
94.8 147.7 47.9 155.5 212.5 184.9 182.4 187.8 205.4 92.1 168.0 241.1 161.5 198.2 60.3 59.1 64.7 141.7
215.1 83.2 72.5 118.0 192.3 184.9 174.5
232.6 99.5 238.2 84.1 188.3 54.7 47.4 221.7 65.4 145.1 167.3 128.2 168.1 188.2 203.7 210.0 190.0
210.7 83.1 190.1 121.2 67.3 62.2
Nov 7 '12 #1
2 2685
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

I have no idea what your error message is as you didn't post the full message.
Nov 7 '12 #2
weaknessforcats
9,208 Expert Mod 8TB
I'm guessing you used arr without initlializing it with a valid address.
Nov 7 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Francesc Guim Bernat | last post by:
Dear colleagues, i'm getting in troubles using one XML library with Visual Studio .NET and Xerces with Xalan. (Xercer 2.4 and Xalan 1.7) When i execute the code i get the next run time error: ...
3
by: AP | last post by:
Hi, I get this exception everytime I debug and is just annoying. "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a...
1
by: Francesc Guim Bernat | last post by:
Dear colleagues, i'm getting in troubles using one XML library with Visual Studio .NET and Xerces with Xalan. When i execute the code i get the next run time error: "Run-Time Check Failure #2...
8
by: Antony | last post by:
compiler£ºVisual Studio.Net 2003 (VC7.1) compile type£ºDebug problem: wanted more information about the "Run-Time Check Failure #n",thanks! Example1: #include "stdafx.h" void malice() {...
2
by: Chris Stankevitz | last post by:
Hi, MSVC 7.1 .net 2003, native c++. I received this runtime message today for the first time in my life (and I've used MSVC for a long time): Run-Time Check Failure #3 - The variable...
2
momotaro
by: momotaro | last post by:
this is the error message that i kep having: Run-Time Check Failure #3 - The variable 's' is being used without being initialized. and this is the part of the code concerned: void...
0
by: PH.D.Condidater.Li.Ning | last post by:
Hi, all, I am using an uninitialised variable that generating a 'Run-Time Check Failure #3' when the debug version is running. The code is complex and changing it would be risky, so how do I...
4
by: PH.D.Condidater.Li.Ning | last post by:
Hi, all, I am using an uninitialised variable that generating a 'Run-Time Check Failure #3' when the debug version is running. The code is complex and changing it would be risky, so how do I...
1
by: 22dude | last post by:
it says the variable hours is being used with out being initializes i am using C++ 2005 express edition , I am currently student Please help me out to find the solution on my code below #...
0
by: Zac Burns | last post by:
Sorry everyone, I found the bug in my code shortly after posting here. For the curious: I was using a QString (pyqt) inadvertently in the lookup. I guess the behavior then would be would be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.