When I comment out the bizarre NULL comparison, it compiles with no warnings, or errors, and functions correctly for foo/bar = 0 , and bar /balls = 2. Here's the full code:
Code:
#include <stdio.h>
#include <string.h>
int longestCommonPrefix(const char *a, const char *b);
int main(void)
{
int c = longestCommonPrefix("bar","balls");
printf("longest prefix: - %i",c);
return 0;
}
int longestCommonPrefix(const char *a, const char *b)
{
int size,sizea, sizeb;
int com=0;
int i=0;
sizea=strlen(a);
sizeb=strlen(b);
// if(sizea==NULL||sizeb==NULL){//probably wrong
// return com;}
if(sizea==0||sizeb==0){
return com;}
if(sizea>=sizeb){
size=sizea;}
if(sizea<sizeb){
size=sizeb;}
for(i=0; i<size; i++){
if(a[i] != b[i]){
return com;
break;}
com++;}
return com;
}