Q:

C Programming: How to determine an exact match between 2 numbers

I am trying to find the exact match between two numbers and have my counter stop at the first instance when they are not a match. However the code I have written counts the entire string length of my numbers.  Is there an alternative way to do this?
Since my counter is starting from the first decimal place and not 0. , it counts to 15 but should stop at 10.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int main(){    
    char str[100];
    char buf[100];

    double l,m,a,b;

    int c,d,t,u,r,q;
    int count =0;

    l=59874.141715197809000;
    m=59874.141715197817000;

    a= (l - (int)l);
    b= (m -(int)m);

    sprintf(str,"%.15f",a);
    sprintf(buf,"%.15f",b);

    c = strlen(str);
    d = strlen(buf);

    for(t=3;t<c;t++){
        for(u=3;u<d;u++){
            if(str[t]==buf[u]){
                count++;
                break;
            }
        }
    }
    printf("matching decimal places = %d \n",count);
    return 0;
}

A:

First, when comparing two strings, you only need to iterate to the length of the smallest string if the two strings differ in length.. That is, if you want to count the amount of sequential character matches in a string.
For example:
A = 0.99997552
B = 0.9999753

would need one for loop to compare.. You would only iterate up to the length of B to determine that 6 decimals match. Why? Because going any further is irrelevant since none of the extra digits would exist in B. Iterating past the end of an array is undefined behaviour anyway. 
In your case both buffers are the same length so no worries there, but again, the shorter string won't have the extra digits found in the longer string.. Hence: Iterate up to the smallest length.
The solution can be done as follows:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int main() {

    //Create large enough buffer to hold 100 digits/characters..
    char str[100] = {0};
    char buf[100] = {0};

    //Two doubles to be compared..
    double l = 59874.141715197809000;
    double m = 59874.141715197817000;

    //Counter keeps track of matching digits..
    int count = 0;

    //Get rid of the base and keep only the decimals..
    double a = (l - (int)l);
    double b = (m - (int)m);

    //Copy a maximum of 15 decimal places to `str` and `buf`
    sprintf(str, "%.15f", a);
    sprintf(buf,"%.15f", b);

    //Get the length of both strings..
    int c = strlen(str);
    int d = strlen(buf);

    //If C is smaller, iterate to length(c) else iterate to length(d).
    for (int i = 2; i < (c < d ? c : d); ++i)
    {
        //If the two characters match, increment the count..
        if (str[i] == buf[i])
        {
            ++count;
        }
    }

    //Print the amount of matching decimals..
    printf("matching decimal places = %d \n", count);
    return 0;
}

