Debug assertion failed problem

Reply

Join Date: Dec 2006
Posts: 7
Reputation: Aleczz is an unknown quantity at this point 
Solved Threads: 0
Aleczz Aleczz is offline Offline
Newbie Poster

Debug assertion failed problem

 
0
  #1
May 16th, 2008
I have a debug assertion failed problem with akrip code. That code is downloadable from http://akrip.sourceforge.net/simple.c


I have add a new code to function RipAudio(...) where i want to add new folder and name the file to it.
  1. void RipAudio( HCDROM hCD, DWORD dwStart, DWORD dwLen, int song )
  2. {
  3. DWORD dwStatus;
  4. FILE *fp;
  5. DWORD num2rip = 26;
  6. int retries;
  7. LPTRACKBUF t;
  8. int c = 0;
  9. DWORD numWritten = 0;
  10. char songname[MAX_PATH-1] = {0};
  11. char str[MAX_PATH-1] = {0};
  12. char temp[] = "Songs";
  13.  
  14. t = NewTrackBuf( 26 );
  15. if ( !t )
  16. return;
  17.  
  18. GetCurrentDirectory(MAX_PATH, str);
  19. CreateDirectory(temp, NULL);
  20. sprintf(str, "%s%s", str, temp);
  21. sprintf(str, "%s\\track%d.wav", str, song);
  22.  
  23. sprintf(songname, "c:\\track%d.wav", song);
  24. // sprintf(songname, str, song);
  25. fp = fopen( str, "w+b" );
  26.  
  27. writeWavHeader( fp, 0 );
  28.  
  29. printf( "Beginning to rip %d sectors starting at sector %d\n", dwLen, dwStart );
  30.  
  31. while( dwLen )
  32. {
  33. if ( !( c++ % 5) )
  34. printf( "%d: %d\n", dwStart, dwLen );
  35.  
  36. if ( dwLen < num2rip )
  37. num2rip = dwLen;
  38.  
  39. retries = 3;
  40. dwStatus = SS_ERR;
  41. while ( retries-- && (dwStatus != SS_COMP) )
  42. {
  43. t->numFrames = num2rip;
  44. t->startOffset = 0;
  45. t->len = 0;
  46. t->startFrame = dwStart;
  47. dwStatus = ReadCDAudioLBA( hCD, t );
  48. }
  49. if ( dwStatus == SS_COMP )
  50. {
  51. fwrite( t->buf + t->startOffset, 1, t->len, fp );
  52. numWritten += t->len;
  53.  
  54. ...

In original code fopen() function save the file to the root of exe but i made it better for me and put it to save the file to the new folder.
The problem is if i try to cange fopen first parameter to str what collect full path to new folder and file in it come to the program some Debug Assertion Failed. That error is in the same RipAudio(...) function but in fwrite function. I dont understand how my fopen- function affect with fwrite- function.
Error message gives "Expression: (stream != NULL)" message of fwrite.c. Is my getcurrentdirectory - createdirectory code right?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Debug assertion failed problem

 
0
  #2
May 16th, 2008
> fp = fopen( str, "w+b" );
This (in all probability) returned NULL, which you then passed on (unchecked) to another function.
Where on receiving NULL, it asserted and told you what was wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 7
Reputation: Aleczz is an unknown quantity at this point 
Solved Threads: 0
Aleczz Aleczz is offline Offline
Newbie Poster

Re: Debug assertion failed problem

 
0
  #3
May 19th, 2008
Originally Posted by Salem View Post
> fp = fopen( str, "w+b" );
This (in all probability) returned NULL, which you then passed on (unchecked) to another function.
Where on receiving NULL, it asserted and told you what was wrong.

I was not sharp enough. The path build was wrong.
sprintf(str, "%s%s", str, temp); ---> sprintf(str, "%s\\%s", str, temp);
So it returns NULL to FILE.
But now it works. Thank you a lot.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC