Im not sure whats wrong wth the code
Code:
//constants
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define RANDOM 256
#pragma warning(disable: 4996)
int main(int argc, char *argv[])
{
//declarations
char MiscNumbers[RANDOM];
int data = 0;
int sum = 0;
int range = 0;
float mean = 0.0;
float variance = 0.0;
float deviation = 0.0;
FILE *fp;
FILE * outFileHandle = NULL;
fp = fopen("\\zeus\profile$\955290767\Desktop\StdDev\one.dat" , "r");
if (fp == NULL)
{
strncpy(one.dat, argv[1], RANDOM);
}
else
{
puts("Enter the name of the file to read (source):");
fgets(one.dat, RANDOM, stdin);
if(one.dat[strlen(one.dat) - 1 == '\n')
prog2a[strlen(prog2a) - 1] = '\0';
else
while(getchar() != '\n');
}
fp = fopen(argc[0], "r");
if(fp == NULL)
{
printf("Could not open file %s for input.\n"
"Press any key to Continue" , one.dat );
getchar();
return EXIT_FAILURE;
}
while (fscanf(fp, "%d" , &numberInSet) != EOF)
{
printf("The results from file dat1.dat are: /n");
printf("--------------------------------------- /n");
printf("| # of data | Sum | Range | Mean | variance | standard deviation | /n");
for (i=0; i<numberInSet; i++)
{
printf("| %d | %d | %d to %d | %f | %f | %f | /n");
}
}
//calculations
//bring the numbers from the file copy it to the arrays and store it. then
//close the file and calculate all the rest
getchar();
return EXIT_SUCCESS;
I know i havent worked on the calculations yet but i asked the compiler to bring a file from a place but that file name Which is one.dat, compiler cant seem to find it or something cause its unidentified.
Re: Im not sure whats wrong wth the code
Are you saying that it fails to open one.dat? Is that network resource accessible from your computer? Can you take that very path and navigate to it in your OS?
Re: Im not sure whats wrong wth the code
the one.dat, "one" part is highlighted in red
Re: Im not sure whats wrong wth the code
I take it you are using visual studio?
Re: Im not sure whats wrong wth the code
What is the error message?
Re: Im not sure whats wrong wth the code
Are you certain you have the file in the location you are trying to open it from?
Furthermore, it would help if you said what the error message says, as I cannot solve a problem when I don't quite understand what the problem is.
Re: Im not sure whats wrong wth the code
at first I thought it was the fopen command where it was failing... it isn't.... the problem is this line:
fgets(one.dat, RANDOM, stdin);
you need to look at the documentation for fgets... I'm quite certain that the first value isn't correct... I think it's supposed to be the stream to the file... in this case ,that's fp ....
wait.... wait.... ughnrgh..... you're using one.dat like it means something.... you've used it in the strncpy and other places... it doesn't work like that... one.dat is just a name of a file... it has no meaning to the code.
in addition, some of your logic doesn't make sense... you're opening a file on the network... if it can't you're doing a string copy... if it can, you're then asking them for the file to open? whaaa? The nyou try to open that file with the same file pointer as the first one with out first closing the original file pointer?
-tg