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

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