阅读背景:

在C中计算文本文件中的关键字

来源:互联网 
#include <stdio.h>  
#include <stdlib.h>
#include <string.h>


int c;

char* lib[5] = { "auto", "break", "char", "case", "const" };
char str[1000];
char buffer[300];
FILE *fp;

int main(){

    c = 0;

    fp = fopen("filename.txt", "r");

    if (fp == NULL){
        perror("Error in reading file");
    }

    if (fp != NULL){
        for (int j = 0; j < 5; j++){
            while (fgets(str, sizeof(buffer), fp) != NULL){
                if (strstr(str, lib[j]) != NULL) {
                    c++;
                }
            }
        }
        printf("%d", c);
    }
    while (1){};
}
#include <stdio.h>  
#include <stdlib.h>
#inclu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: