I found a whole slew of errors in this program. 14 to be exact, and a few warnings. Well, here goes.
You need a main function, every program must have a main function unless it is a header file to a driver that has the main function. Be sure to add this and do all of your input there, then call your str_count function.
>if(source[i]=target[1]
&&ources[i+1]=target[2]&&
source[i+2]=target[3]&&souce[i+3]=target[4])
Think of the = sign as meaning 'is now'. Is source[i] = target[1]? It is now! The = sign is used for assignment, you were trying to assign the value of target[1] to source[i] and this is illegal. Even if it weren't, the effect would be anything but what you wanted. Use == for comparisons.
You also spelled your array name incorrectly not once in that line, but twice. Always double check your spelling and you will be saved a lot of errors.
>return (count);
Use this at the end of your function, not after the if statement. If you left it this way you would perform the if statement once and then leave the function. As it is you want the function to perform it's duties completely before returning and that means returning outside of the loop.
Here's the same program with the necessary changes, I did not check to see if it worked properly, only compiled without errors or warnings.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int str_count(const char *source, const char *target)
{
int i, count=0;
for(i=0; i<12;i++)
{
if(source[i]==target[1] && source[i+1]==target[2] && source[i+2]==target[3] && source[i+3]==target[4])
{
count=count+1;
}
else
{
return 0;
}
}
return (count);
}
int main() {
char source[12], target[4];
/*input source string*/
printf("input source string");
gets(source);
printf("input target string");
gets(target);
str_count(source, target);
return 0;
}