Search
 
SCRIPT & CODE EXAMPLE
 

C

how to search in a file in c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
int num =0;
char word[2000];
char *string[50];

FILE *in_file = fopen("student.txt", "r");
//FILE *out_file = fopen("output.txt", "w");

if (in_file == NULL)
{
    printf("Error file missing
");
    exit(-1);
}

while(student[0]!= '0')
{
    printf("please enter a word(enter 0 to end)
");
    scanf("%s", student);


    while(!feof(in_file))
    {
        fscanf(in_file,"%s", string);
        if(!strcmp(string, student))==0//if match found
        num++;
    }
    printf("we found the word %s in the file %d times
",word,num );
    num = 0;
}

return 0;
 } 
Comment

PREVIOUS NEXT
Code Example
C :: c boolean 
C :: data types in c 
C :: add border to image android 
C :: yourkill071 
C :: see if two strings are equal in C 
C :: first program in c 
C :: arduino digital input pins 
C :: how to genrate a random number in C 
C :: libdvd-pkg: `apt-get check` failed 
C :: que es % en c 
C :: c round function 
C :: c convert number to string 
C :: matplotlib plot circle marker 
C :: get last char string c 
C :: c programing strtok use 
C :: mongodb update 
C :: initialize array in c with 0 
C :: Gemfile.lock`. It is likely that you need to grant write permissions for that path. 
C :: c sleep milliseconds 
C :: plt legend top right outside 
C :: star pattern in c 
C :: c code to grade marks 
C :: how to make a check bigger 
C :: read file c 
C :: c calculate median 
C :: c program to implement mv command 
C :: how to free memory in c 
C :: strstr 
C :: finding characters in string 
C :: stack pop 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =