How can I fix runtime error ,In c


  • 0
    T
    char* CutDchar(char* source)
    {
    	char* result =(char *)malloc(sizeof(char)*60) ; 
    	strcpy(result,""); 
    	int j =  strlen(source);
    	char NotDsource[60] = {0}; 
    	int m; 
    	int inflag; 
    	for( m=0;m<=j;m++)
    	{
    		inflag=0; 
    		int NDcs=strlen(NotDsource) ;
    		int ND1; 
    		for(ND1=0;ND1<=NDcs;ND1++)
    		{
    			if (NotDsource[ND1]==source[m])
    			{
    				inflag=1; 
    			} 
    		} 
    		if(inflag==0)
    		{
    			NotDsource[NDcs]=source[m]; 
    		} 
    
    	} 
    	int l =  strlen(NotDsource);
    	int ncs; 
    	strcat(result,NotDsource); 
    	return result; 
    
    		
    }
     
    char* getHint(char* secret, char* guess)
    {
    	char cowsecret[80] = {0}; 
    	char cowguess[80] = {0}; 
    	char intoc[5]; 
    	char resultformate[]="0A0B"; 
    	char* result =(char *)malloc(sizeof(char)*10) ; 
    	strcpy(result,""); 
    	int n = strlen(secret); 
    	int numbulls = 0;
    	int numcows = 0;
    	int numcowsecret=0;
    	int numcowguess =0; 
    	int i; 
    	for( i = 0; i<n ; i++)
    	{			
    		if (secret[i]==guess[i])
    		{
    			numbulls++;
    		} 
    		else if(secret[i]!=guess[i]) 
    		{
    			cowsecret[numcowsecret]=secret[i];
    			cowguess[numcowguess]=guess[i];
    			numcowsecret++;
    			numcowguess++; 
    		} 
    
    	} 
    	char* psecret= CutDchar(cowsecret); 
    	int npsecret=strlen(psecret);
    	char* pguess= CutDchar(cowguess); 
    	int npguess=strlen(pguess);
    	int tmps;
    	int tmpg; 
    	for (tmps=0;tmps<npsecret;tmps++)
    		{
    			for(tmpg=0;tmpg<npguess;tmpg++)
    			{
    				if (psecret[tmps]==pguess[tmpg])
    				 {
    				    numcows++;
    				 } 
    			} 
    		} 
    	
    	sprintf(intoc,"%d",numbulls);
    	resultformate[0]=intoc[0]; 
    	sprintf(intoc,"%d",numcows); 
    	resultformate[2]=intoc[0]; 
    	strcat(result,resultformate); 
    	free( psecret);
    	free( pguess); 
    	return result; 
    	
        
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.