C Code Question


  • 0
    Z

    I tried sprintf and strcpy, and they all don't work.

    char** findRestaurant(char** list1, int list1Size, char** list2, int list2Size, int* returnSize) {
        char** result=(char**)malloc(sizeof(char*));
        if((**list1==NULL)||(**list2==NULL))
        {
            * returnSize=0;
            return NULL;
        }
        else
        {
            int temp=3000;
        for(int i=0;i<list1Size;i++)
        {
            for(int j=0;j<list2Size;j++)
            {
                if(!strcmp(list2[j],list1[i]))
                {
                    if((i+j)<temp)
                    {
                        sprintf(result[0],"%s",list1[i]);//how to?
                        temp=i+j;
                        break;
                    }
                }
            }
        }
            if(temp=3000)
            {
             * returnSize=0;
            return NULL;
            }
            else{
            * returnSize=1;
            return result;
            }
            
        }
        
    }
    

Log in to reply
 

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