How to read a text file line by line and print only the lines that not include a specific word in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main() {
    FILE* fp = fopen("d:\\data.txt", "r");
    char line[80];

    if (!fp) {
        puts("File doesn't exist");
        return 1;
    }

    // char *strstr (const char *str1, const char *str2);
    // returns a pointer to the first characters of str2 in str1 or null pointer if not found

    while (fgets(line, sizeof(line), fp)) {
        if (!strstr(line, "Java")) { // ! include 
            printf("%s", line);
        }
    }
	
    fclose(fp);

    return 0;
}




/*
run:

C C++ Python
C#
C++ is a high-level
Is Rust harder than Python
Visual Studio C/C++ IDE
Learn C
C Programming

*/

 



answered Oct 31, 2024 by avibootz

Related questions

1 answer 157 views
1 answer 162 views
162 views asked Apr 8, 2021 by avibootz
2 answers 243 views
...