this is coming off a program that collects information and saves it after every command. I have opened my file successfully cause thats how it reads the client. the problem is saving the data. Does this code look right to everybody??? I am running in C and very very basic. I am very new, but anyways let me know what you think!

Thanks

void SaveData (char Name[], double E_Data[]) { 

// Local Variables 
  double endofFile =        0.0;
  double FileValue =        0.0;
  FILE *fileHandle;
  int i = 0;


  // Begin
  //Get File
  fileHandle = fopen(Name,"w");

  if (fileHandle == NULL){
	printf("\nSaving Error!\n");
  } //end if
  else{
    for (i = 0; i < 18; i++){
      fprintf(fileHandle,"%f ",E_Data[i]);
	} // end for loop
  } // end else statment
  
  fclose(fileHandle);


} // end SaveData

Please use the code tags properly and preview your post.
[code=C]

[/code]
And run your program and see what comes up, at a glance it seems ok.

PS. remove the \ in the code tag I have shown.

At a guess I'd say that fileHandle = fopen(Name,"w"); should be changed to "a" or something. If the function's being called more than once you'll want to append data to the file rather than write to a clean file, right?

what's the problem saving the data? as in, what's it doing or not doing that doesn't seem right to you?

if you want a new file to be written with the data, then you're using fopen correctly.... "w" (write) will delete the contents of the existing file, if any, before writing the new data.

if you want the file to continually add new data to the existing file, then you need to use "a" (append) as poster above noted.

otherwise, the only other problem that could be happening, is that your double floating point array being passed into E_Data might not be containing what you think it should be. for instance if it's uninitialized, any number of weird behaviors could be occuring.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.