Pagini recente » Cod sursa (job #2982661) | Cod sursa (job #953332) | Cod sursa (job #1673080) | Cod sursa (job #2375262) | Cod sursa (job #2555433)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fin, *fout;
void find(char *tofind, char *s)
{
long int nr = 0, nrp = 0, positions[1000000];
char *p = strstr(s, tofind);
if(p == NULL)
{
fprintf(fout,"%ld",nr);
return;
}
nr++;
positions[nrp++] = p - s;
while((p = strstr(p+1, tofind)) != NULL)
{
nr++;
positions[nrp++] = p - s;
}
fprintf(fout,"%ld\n", nr);
for(int i = 0; i < nrp; i++)
{
fprintf(fout, "%ld ",positions[i]);
if(i == 999)return;
}
}
int main()
{
fin = fopen("strmatch.in","r"), fout = fopen("strmatch.out","w");
char s1[2000000], s2[2000000];
/*
fgets(s1, 2000000, fin);
int l1 = strlen(s1);
fgets(s2, 2000000, fin);
s1[l1-1] = '\0';
*/
// putchar('A');
int i = 0, j = 0;
char c;
while((c = fgetc(fin)) != '\n')
{
s1[i++] = c;
}
s1[i] = '\0';
while((c = fgetc(fin)) != EOF && c != '\n')
{
s2[j++] = c;
}
s2[j] = '\0';
find(s1,s2);
fclose(fin);fclose(fout);
return 0;
}