+ 2
how to open file in c with extension not .txt?
for example i want to open file.abc
4 Antworten
+ 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
+ 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);
+ 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.