Creepzzz
Creepzzz

Reputation: 1

How do you fix debug assertion failed?

I'm making a C program that is changing all the non alphabet questions to a space. But when I run it I get the debug assertion failed message. How can I solve it? Here is my code:

int main(void) {
    FILE* txtFileR = fopen("alg3file.txt", "r");
    FILE* txtFileW = fopen("destAlg3.txt", "w");

    int c;

    while ((c = fgetc(txtFileR)) != EOF) {
        if (isalpha(c)==0 && c!='\n') {
            c = ' ';
        }
        fputc(c, txtFileW);
    }
    fclose(txtFileR);
    fclose(txtFileW);
}

enter image description here

Upvotes: 0

Views: 761

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126438

Most likely, one of your fopen calls failed and returned a NULL FILE *. When you pass that fgetc or fputc, you get undefined behavior, which in your case shows up as a debug assertion about an invalid stream.

Upvotes: 3

Related Questions