⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 88.c

📁 计算概论阅读材料
💻 C
字号:
#define LINE 20#define N 80#include <stdio.h>#include <string.h>#include <alloc.h>#include <stdlib.h>FILE *fp;char fname[12];readln(char *pl[])//read filename and return total of lines{	int nl=0,i;	char *p,s[80];	while(fgets(s,80,fp)!=NULL)		if((p=(char*)malloc(strlen(s)+1))==NULL) return -1;	else{		strcpy(p,s);		pl[nl++]=p;	}	return nl;}search(char *pl[],int nl,char *str){	int top=0,bottom=nl-1,mid,f;	while(top<=bottom){		mid=(top+bottom)/2;		f=strcmp(str,pl[mid]);		if(f==0)			return mid;		else			if(f<0)bottom=mid-1;			else top=mid+1;	}	return -1;}void main(void){	char *pl[LINE],book[N];	int nl,k;	gets(fname);	if((fp=fopen(fname,"r"))==NULL){		printf("Can't find file \n");		exit(1);	}	if((nl=readln(pl))>=0){		gets(book);		strcat(book,"\n");		k=search(pl,nl,book);		if(k!=-1) printf("%d %s\n",k,pl[k]);		else printf("Can't find the string\n");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -