+ 2

how to open file in c with extension not .txt?

for example i want to open file.abc

16th Dec 2018, 3:17 AM
arase
3 Réponses
+ 2
I don'tknow in c , but in c++ we use the fstream library. #include <fstream> std::string str; // for reading ifstram file("file.ABC"); file >> str; // To write ofstream file2("file.abc"); file2 << "stuff"; There are other methods as well
16th Dec 2018, 5:43 AM
voidneo
+ 2
Other method may be using strinstreams #include <sstream> stringstream ss( file ); // Read a word ss >> str; // Read many words ss >> str >> str2 >> ... // Read full line getline(ss, str);
16th Dec 2018, 5:51 AM
voidneo
+ 1
In C you specify the file name and extension with an optional directory path. For example, to open "\home\user\directory\file1.abc" you would use "\\home\\directory\\file1.abc". Any spaces or special characters need to be escaped like \" to include a " in the file name. There is nothing special about the extension, except that some programs expect and default to a specific extension if one is not specified. End the file name with a . if you don't want the program to append the default extension when you don't supply one.
1st Feb 2019, 4:52 AM
Roger Greenlaw