hi, I am trying to recreate the strncmp function without actually using the function from the library I have to come up with the solution.so far i can compare the complete strings but I haven't figured out how to compare only a portion with a given number when the function is called . This is my function it can compare the entire sentences but im not sure about the n value,perhaps i might be missing something?when the function is called in main it is suppose to return 1;
It would be a lot easier to read this code if you used S1[i] and S2[i] instead of *(S1+i) and *(S2+i).
Going left to right in the condition at line 4, you know that S1[i] == S2[i], so there's no need to check both S1[i] != 0 and S2[i] != 0. Since you know they're equal, you only need to check one.
(n<i) should be (i<n)
After the fix that ne555 mentioned, the return can be simply return S1[i] - S2[i];