C - how to delete string the same string as user input from a file in c?

Gio

I want to make a program that delete a String that the same as user input from a file below are contents in the file

G12
G13
G14

For example user input G13 , expected output is as following :

G12
G14

I got some idea that make a temporary file , but don't get any idea on how to get a string line by line because i print the file content using these code

if(file!=NULL)
{
    while ((c = getc(file)) != EOF)
    putchar(c);
    fclose(file);
}

so basically i reads all the file content only letter by letter (dont have any idea how to make it reads word by word

Thanks in advance

BLUEPIXY

simple line by line sample

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

char *esc_cnv(char *str){
    char *in, *out;
    out = in = str;
    while(*in){
        if(*in == '\\' && in[1] == 'n'){
            *out++ = '\n';
            in += 2;
        } else 
            *out++ = *in++;
    }
    *out = '\0';
    return str;
}

int main(void){
    FILE *fin = stdin, *fout = stdout;
    char line[1024];
    char del_str[1024];
    char *p, *s;
    int len;
    int find=0;//this flag indicating whether or not there is a string that you specify 

    fin = fopen("input.txt", "r");
    fout = fopen("output.txt", "w");//temp file ->(delete input file) -> rename temp file.
    printf("input delete string :");
    scanf("%1023[^\n]", del_str);
    esc_cnv(del_str);//"\\n" -> "\n"
    len = strlen(del_str);
    while(fgets(line, sizeof(line), fin)){
        s = line;
        while(p = strstr(s, del_str)){
            find = 1;//find it!
            *p = '\0';
            fprintf(fout, "%s", s);
            s += len;
        }
        fprintf(fout, "%s", s);
    }
    fclose(fout);
    fclose(fin);
    if(find==0)
        fprintf(stderr, "%s is not in the file\n", del_str); 
    return 0;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Write user input string to file in C

From Dev

Reading string input from file in C

From Dev

User input string variable in C

From Dev

Delete User Input from the Terminal in C

From Dev

How to add line or string in the host file and also find and delete specific string from the host file using C#?

From Dev

How to double a float/integer within a user input string in C?

From Dev

How to store user string input in array, C++

From Dev

How to read and delete string between specific characters from file in c++

From Dev

how to load a c string from a file

From Dev

Get string from input file until integer? C++

From Dev

Read from a input file until a string appears in C++

From Dev

C++ String user input into Class Object?

From Dev

Count words in a user-input string in C

From Dev

Count words in a user-input string in C

From Dev

Append to C String Based on User Input

From Dev

User string input to go until \0 in c

From Dev

String concatenation with user input in C++

From Dev

How to read a .txt file from user input in C

From Dev

How to correctly input a string in C

From Dev

How to extract a certain string and delete rest of values from an input string?

From Dev

How can I delete a word from a String in Visual C#

From Dev

Storing MySQL Connection String in Variables from User Input then Building String [C#]

From Dev

How to delete a string from a file in bash

From Dev

how to delete the string from the file in unix

From Dev

How to delete a string from a file in bash

From Dev

How can I remove 'garbage input' from a C string?

From Dev

C++ How to check if string starts with char from input

From Dev

Delete string from computer memory in C#

From Dev

Delete first word from string on C

Related Related

  1. 1

    Write user input string to file in C

  2. 2

    Reading string input from file in C

  3. 3

    User input string variable in C

  4. 4

    Delete User Input from the Terminal in C

  5. 5

    How to add line or string in the host file and also find and delete specific string from the host file using C#?

  6. 6

    How to double a float/integer within a user input string in C?

  7. 7

    How to store user string input in array, C++

  8. 8

    How to read and delete string between specific characters from file in c++

  9. 9

    how to load a c string from a file

  10. 10

    Get string from input file until integer? C++

  11. 11

    Read from a input file until a string appears in C++

  12. 12

    C++ String user input into Class Object?

  13. 13

    Count words in a user-input string in C

  14. 14

    Count words in a user-input string in C

  15. 15

    Append to C String Based on User Input

  16. 16

    User string input to go until \0 in c

  17. 17

    String concatenation with user input in C++

  18. 18

    How to read a .txt file from user input in C

  19. 19

    How to correctly input a string in C

  20. 20

    How to extract a certain string and delete rest of values from an input string?

  21. 21

    How can I delete a word from a String in Visual C#

  22. 22

    Storing MySQL Connection String in Variables from User Input then Building String [C#]

  23. 23

    How to delete a string from a file in bash

  24. 24

    how to delete the string from the file in unix

  25. 25

    How to delete a string from a file in bash

  26. 26

    How can I remove 'garbage input' from a C string?

  27. 27

    C++ How to check if string starts with char from input

  28. 28

    Delete string from computer memory in C#

  29. 29

    Delete first word from string on C

HotTag

Archive