rushabh sojitra
rushabh sojitra

Reputation: 152

Dev c++ creates test.txt , when i create a txt file using FILE

i have been practicing c in the emulator in my windows 10. Later I switched to dev C++ IDE. When I was working with FILE in C . The file which is created gets a name test.txt , while I have given some other name. kindly help through it.

Here is the code below :

int main()
{
    FILE *fp;
    char c;
    char buff[255];
    fp=fopen("text.txt","wr");
    fputs("one\ntwo\nthree\nfour",fp);
    fclose(fp);
    return(0);
}

All I am getting is test.txt for every different file name

Upvotes: 0

Views: 333

Answers (1)

Curious Student
Curious Student

Reputation: 70

The problem is about the opening mode, you can refer to @Amar Srivastava's answer on this stackoverflow question: File opening modes in C++

edit: i know the post above is about c++ but the opening modes in c and c++ are really the same

Upvotes: 1

Related Questions