Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


fprintf in C help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
407
Master Cheater
Reputation: 0

Joined: 25 Oct 2007
Posts: 357

PostPosted: Sun Jan 23, 2011 4:57 pm    Post subject: fprintf in C help Reply with quote

Code:
void results(FILE* in, char studentAns[], char ansKey[], int studentId[])
{
   
   FILE* out;
   out = fopen("grades.txt", "w");
   
    if(out == NULL)
    {
        printf("Error opening file.\n");
    }

   fprintf(out, "ID\tNumber Correct\tPercent");

   return;
}


It's not printing for some reason.. I can't seem to see what the problem is..
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jan 23, 2011 5:45 pm    Post subject: Reply with quote

It works fine. I just made this short program:
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {   
  FILE* out;
  out = fopen("grades.txt", "w");

  if(out == NULL)
  {
    printf("Error opening file.\n");
  }

  fprintf(out, "ID\tNumber Correct\tPercent");
  fclose( out );

  return 0;
}


Something to note, you are missing a fclose() at the end.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Jan 23, 2011 5:57 pm    Post subject: Reply with quote

If you don't close the file handle, I don't think it will write to the file. I had that issue in java the other day.
_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Jan 23, 2011 6:00 pm    Post subject: Reply with quote

Nope it works without the fclose. Also your check for the fopen is good practice but not wrapping the rest of it in an else or making it return in the case of error is not.
Back to top
View user's profile Send private message
407
Master Cheater
Reputation: 0

Joined: 25 Oct 2007
Posts: 357

PostPosted: Sun Jan 23, 2011 8:34 pm    Post subject: Reply with quote

Slugsnack wrote:
Nope it works without the fclose. Also your check for the fopen is good practice but not wrapping the rest of it in an else or making it return in the case of error is not.
That's what I thought..
I need 2 parallel files open, because I can't re-start where I left off if I close the file, right?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Jan 23, 2011 11:08 pm    Post subject: Reply with quote

Two wrote:
Slugsnack wrote:
Nope it works without the fclose. Also your check for the fopen is good practice but not wrapping the rest of it in an else or making it return in the case of error is not.
That's what I thought..
I need 2 parallel files open, because I can't re-start where I left off if I close the file, right?


If you wrote to the end of the file just set the file pointer to the end. Look into:
fseek / fsetpos

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites