943,736 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1694
  • C RSS
May 16th, 2008
0

Debug assertion failed problem

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aleczz is offline Offline
7 posts
since Dec 2006
May 16th, 2008
0

Re: Debug assertion failed problem

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 19th, 2008
0

Re: Debug assertion failed problem

Click to Expand / Collapse  Quote originally posted by Salem ...
> 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Aleczz is offline Offline
7 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: buffer to upper case?
Next Thread in C Forum Timeline: Loading a structure (text lines) from a file, modify the structure, then save





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC