Thread: debug assertion failed!

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    78

    debug assertion failed!

    Hi experts,

    i am facing this error in runtime

    debug assertion failed!
    FILE fgets.c
    line 60
    Expression str!= NULL







    my code is pasted below can anyone help me?


    Code:
    
    /* Include files */
    #include <stdio.h>
    #include <uf.h>
    
    #include<stdio.h>
    #include<conio.h>
    #include<uf.h>
    #include<uf_csys.h>
    #include<uf_ui.h>
    #include<uf_curve.h>
    #include<uf_vec.h>
    #include<uf_part.h>
    #include<uf_drf.h>
    #include<string.h>
    #include<stdlib.h>
    #include<uf_defs.h>
    
    #include <ERRNO.H>
    #include <direct.h>
    #include <math.h>
    #include <io.h>
    #include <stdarg.h>
    #include <time.h>
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <sys/stat.h>
    #include <assert.h>
    
    
    static void my_block();
    extern void main( char argc, char *argv[] )
    {
       my_block();
    	
       
    }
    
    static void my_block()
    {
    
    
    	FILE *fp;
    	float x,y,z;
    	long int i=0,n=0,j=0,k=0;
    	char buf1[1000];
    	double x_cor[5];
    	double y_cor[5];
    	double z_cor[5];
    	const char  *str1;
    	tag_t  part;
    		struct point{
    
    		double pt[3];
    	};
    
    	int no_of_section,no_points,count=0;
    	int	degree=3;
    	int	periodicity=0;
    	int	save_def_data = 0;
    	int num_points=5;
    	struct point tempPts;
    	tag_t	spline_tag=NULL_TAG;
    
    	
    	UF_CURVE_pt_slope_crvatr_t point_data[5];
    
    	//buf1 = (char *)malloc (sizeof(char*));
    
    	fp = fopen("D:\\Backup_QI-287\\GEConfidential\\rajesh\\material_code_table\\javed\\Runner_Blade.txt", "r");
    	
    //(fgets(line, 80, fr) != NULL)
    
    	
    	
    	while (((str1 = fgets( buf1, 1000, fp ))!= NULL)&&(k != EOF ))
    	{		
    										
    			i = strlen(buf1);
    			//printf("\n Final val : &#37;d",i);
    		
    			
    				if(n==1)
    				{
    					sscanf(str1,"%d %d",&no_of_section,&no_points);
    					printf("\n No of Section: %d\n",no_of_section);
    					printf("\n No Points: %d\n",no_points);
    				}
    			
    			   if(n>1)
    				{
    					
    					sscanf(str1,"%f %f %f",&x,&y,&z);
    					//printf("\n Final val : %.3f %.3f %.3f",x, y, z);
    					
    					tempPts.pt[0]=x;
    					tempPts.pt[1]=y;
    					tempPts.pt[2]=z;
    						
    					j++;
    					printf("\n Final val : %.3f %.3f %.3f",tempPts.pt[0],tempPts.pt[1],tempPts.pt[1]);
    			
    					printf("\n no of line :%d",j);
    					
    
    				}
    						
    				n++;
    
    	}
    	fclose(fp);
    
    /*
    	UF_PART_new("D:\\Pract\\shspline\\d5.prt",1,&part);
    	UF_CURVE_create_spline_thru_pts ( degree,  periodicity, num_points, point_data,  NULL,  save_def_data, &spline_tag );
    
    	UF_PART_save(  );*/
    	
    
    	printf("\nhi i m in block\n");
    
    
    }
    Last edited by chintugavali; 12-10-2007 at 11:15 PM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    yeeeeaaahh... I think you got the wrong file.

    http://faq.cprogramming.com/cgi-bin/...&id=1043284376

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    It seems someone has been cutting and pasting with no idea what's going on

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I'd do a search for a line that has assert( ...
    But since you say it's on line 60 of fgets.c, I'm assuming it's coming from the fgets() function rather than your own code...
    Maybe you should check the value of fp after calling fopen() to see if it actually opened the file...

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > debug assertion failed!
    > FILE fgets.c
    > line 60
    > Expression str!= NULL
    As cpjust has correctly diagnosed, this is telling you that you passed a NULL pointer to fgets(). Since buff1 obviously isn't going to be NULL, and fp is in all likelihood NULL (following a failed fopen), then that would be the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debug Assertion Failed!
    By IndioDoido in forum C Programming
    Replies: 31
    Last Post: 03-25-2008, 11:07 AM
  2. debug assertion failed!
    By chintugavali in forum C++ Programming
    Replies: 5
    Last Post: 12-21-2007, 04:05 AM
  3. Visual Studio 2005 Debug Assertion Failed
    By natmas in forum C++ Programming
    Replies: 7
    Last Post: 07-17-2007, 04:28 PM
  4. debug assertion failed !
    By blue_gene in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2004, 11:23 AM
  5. Debug Assertion Failed!
    By Ray Schmidt in forum C++ Programming
    Replies: 3
    Last Post: 02-21-2003, 09:58 PM