#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
FILE *fp=NULL;
char a[1000];
fp=fopen("D:\\beyond_compare\\test1220.txt","r");
if (fp== NULL)
{
printf("open file stu.txt error\n");
return -1;
}
while(fgets(a,sizeof(a),fp))
{
if((a[43]=='6')&&(a[44]=='C'))
{
FILE *fp2 =fopen("D:\\beyond_compare\\test1221.txt","a+");
fputc(a[0], fp2);
fputc(' ', fp2);
fputc(a[1], fp2);
fputc('\n', fp2);
fclose(fp2);
}
}
fclose(fp);
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int strindex(char source[],char searchfor[]);
char pattern[] = "78";
int main(void)
{
FILE *fp=NULL;
char a[1000];
fp=fopen("D:\\beyond_compare\\test1220.txt","r");
if ( fp== NULL )
{
printf("open file stu.txt error\n");
return -1;
}
while( fgets(a,sizeof(a),fp) )
{
if ( strindex(a,pattern) >=0 )
printf("%s", a );
}
fclose(fp);
system("pause");
return 0;
}
int strindex(char s[],char t[])
{
int i,j,k;
for(i=0;s[i]!='\0';i++)
{
for(j=i,k=0;t[k]!='\0' && s[j]==t[k];j++,k++)
;
if(k>0 && t[k]=='\0')
return i;
}
return -1;
}