code/C/derivative/derivative.c
long int find_factor(char *function)
{
    char k[size] = {0};
    char *ptr;
    ptr = (char*)memchr(function, 'x', strlen(function));
    
    if (!strncmp(function, "x", 1))                             // f(x) = x --> k = 1;
        strncpy(k, "1", 1);
        
    if (ptr!=NULL)                                              // function with x
        strncpy(k, function, ptr-function);
    else                                                        // function without x
        strncpy(k, function, strlen(function));

    k[strlen(k)] = '\0';                                        // add null character at the end

#if (DEBUG == 1)
    printf("[DEBUG] The factor of the function f(x) = %s is %ld!\n", function, atol(k));
#endif
    
    return atol(k);
}
/**
 * find_factor
 *
 * find the factor of a given faction and return it
 *
 * @param   function
 * @return  factor of a function
 */
find_factor
find the factor of a given faction and return it

@param   function
@return  factor of a function
find_factor find the factor of a given faction and return it @param function @return factor of a function
long int find_factor(char *function)
{
    char k[size] = {0};
    char *ptr;
    ptr = (char*)memchr(function, 'x', strlen(function));
    if (!strncmp(function, "x", 1))                             
        strncpy(k, "1", 1);
    if (ptr!=NULL)                                              
        strncpy(k, function, ptr-function);
    else                                                        
        strncpy(k, function, strlen(function));
    k[strlen(k)] = '\0';                                        
#if (DEBUG == 1)
    printf("[DEBUG] The factor of the function f(x) = %s is %ld!\n", function, atol(k));
#endif
    return atol(k);
}
long int find_factor ( char * function ) { char k [ size ] = { 0 } ; char * ptr ; ptr = ( char * ) memchr ( function , ' ' , strlen ( function ) ) ; if ( ! strncmp ( function , " " , 1 ) ) strncpy ( k , " " , 1 ) ; if ( ptr != NULL ) strncpy ( k , function , ptr - function ) ; else strncpy ( k , function , strlen ( function ) ) ; k [ strlen ( k ) ] = ' \0 ' ; #if ( DEBUG == 1 ) printf ( " \n " , function , atol ( k ) ) ; #endif return atol ( k ) ; }
find_factor
 find the factor of a given faction and return it
find_factor find the factor of a given faction and return it
// f(x) = x --> k = 1; // function with x // function without x // add null character at the end