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.

void RipAudio( HCDROM hCD, DWORD dwStart, DWORD dwLen, int song )
{
  DWORD dwStatus;
  FILE *fp;
  DWORD num2rip = 26;
  int retries;
  LPTRACKBUF t;
  int c = 0;
  DWORD numWritten = 0;
  char songname[MAX_PATH-1] = {0};
  char str[MAX_PATH-1] = {0};
  char temp[] = "Songs";

  t = NewTrackBuf( 26 );
  if ( !t )
    return;

  GetCurrentDirectory(MAX_PATH, str);
  CreateDirectory(temp, NULL);
  sprintf(str, "%s%s", str, temp);
  sprintf(str, "%s\\track%d.wav", str, song); 
  
  sprintf(songname, "c:\\track%d.wav", song);
 // sprintf(songname, str, song);
  fp = fopen( str, "w+b" );

  writeWavHeader( fp, 0 );

  printf( "Beginning to rip %d sectors starting at sector %d\n", dwLen, dwStart );

  while( dwLen )
    {
      if ( !( c++ % 5) )
	printf( "%d: %d\n", dwStart, dwLen );

      if ( dwLen < num2rip )
	num2rip = dwLen;

      retries = 3;
      dwStatus = SS_ERR;
      while ( retries-- && (dwStatus != SS_COMP) )
	{
	  t->numFrames = num2rip;
	  t->startOffset = 0;
	  t->len = 0;
	  t->startFrame = dwStart;
	  dwStatus = ReadCDAudioLBA( hCD, t );
	}
      if ( dwStatus == SS_COMP )
	{
	  fwrite( t->buf + t->startOffset, 1, t->len, fp );
	  numWritten += t->len;
	  
...

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?

> 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.

> 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.

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.