Matching patterns of characters
the following does not address any desired updates to findmatch()

But does address the request for improvements to the program.

improvements include:


no implicit conversion warnings from the compiler
does not use a well known system function name
uses system function: strlen() to find the length of the string
does not produce any compiler warnings
uses fgets() to read whole line in one operation
uses strchr() to eliminate any newline read by fgets()
follows the axiom: only one statement per line and (at most) one variable declaration per statement, resulting in much easier to read/understand code
the 'magic' numbers were either eliminated or replaced with meaningful names


and now, the revised code:

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

#define MAX_INPUT_LEN (40)

// prototypes
size_t myReadLine (char* text, int n);
char* findmatch(char* pattern, char* text, size_t pl, size_t tl);
void printmessage(char* position, char* text, size_t pl, size_t tl);

int main( void )
{
    char text[ MAX_INPUT_LEN ];
    char pattern[ MAX_INPUT_LEN ];
    char *position;
    size_t textlength;
    size_t patternlength;

    printf("Enter text: ");
    textlength = myReadLine( text, (int)(sizeof text) );

    printf("Enter pattern: ");
    patternlength = myReadLine( pattern, sizeof pattern );

    position = findmatch(pattern, text, patternlength, textlength);
    printmessage(position, text, patternlength, textlength);
}



size_t myReadLine( char* text, int n)
{
    size_t i = 0; // initialize to no chars read

    if( NULL != fgets( text, n, stdin ) )
    {
        // eliminate trailing newline, if any
        char * newline;
        if( NULL != ( newline = strchr( text, '\n' ) ) )
        {
            *newline = '\0';
        }

        i = strlen( text );
    }
    return i;
}



char* findmatch(char* pattern, char* text, size_t pl, size_t tl)
{
    size_t indexp = 0;
    char* position = NULL;
    size_t x=0;

    for( ; x&lt;tl; x++)
    {
        int pc = *(pattern+indexp);
        int tc = *(text+x);

        if(pc == '?' || pc == tc)
        {
            indexp++;
            if(indexp == pl)
            {
                position = (text+x)-indexp+1;
                break;
            }
            printf("status: pass\n");
        }

        else
        {
            indexp = 0;
            printf("status: fail\n");
        }
    }
    return position;
}


void printmessage(char* position, char* text, size_t pl, size_t tl)
{
    if(position == NULL)
    {
        printf("no match\n");
    }

    else
    {
        size_t p = (size_t)(position-text)+1;
        printf("%s: %ld. %s\n",
               "The pattern was found at char",
               p,
               "The remaining text chars are: ");
        size_t i =  p+pl-1;

        for(; i&lt;tl; i++)
        {
            printf("%c", *(text+i));
        }
        printf("\n");
    }
 }