He said he's using system("reg add") to do it. I've never used either one, but I assume it's a way for a program to add something to the registry. I think he's now looking for a way for a program to enter "y" on the user's behalf, perhaps to confirm a system command invoked by system(). But I don't know of a way to fake console input. Do you?
Result: "Value TestVariable exists, overwrite(Yes/No)?"
If Y is given as input, then "The operation completed successfully.", and the value is updated. But I want to skip the step where the user has to give the Y input, and send it automatically.
At first I was thinking, well if I can't modify it, what if I try to first delete it and then add it with the new value, but I get in the same situation, and that is I have to give it an input because when you want to delete a variable, you have to input Y/N.
• The current LoadFromFile function is incredibly dense and complex, reading dozens of versions of the config file in a backward-compatible manner, which makes duplication of the overall logic quite a pain.
• The functions that generate the config file and those that read it originate in totally different parts of the old system and therefore don't share any data structures so I can't pass those directly. I could potentially write a wrapper, but again, it would need to handle any structure passed in a backward-compatible manner.
• I'm tempted to just pass the file as is in as a string (as in the prototype above) and convert all the fscanf's to sscanf's but then I have to handle incrementing the pointer along (and potentially dealing with buffer overrun errors) manually.
• This has to remain in C, so no C++ functionality like streams can help here
Am I missing a superior choice? Is there a good method for making a FILE * that simply focuses to an area in memory rather than on a disk? Any pointers, ideas or other assistance is enormously valuable.
1. Can I replace curl with another protocol ? (This is not mandatory, could be as it is now)
2. Is there a header only c++ lib that can complete this request ? Of course, I know there is REST SDK library, but it is too much trouble for that simple request.
curl isn't a protocol, as such, but a CLI tool for data transfer using urls. The underpinnings are based on libcurl, a C library, that implements the data trasfer. As such, you can make API calls directly from your C++ program. Another option would be to look into popen() e.g.
FILE *pipe = popen("curl --header \"x-api-key:ABCD\" -s https://api.test.se/api/mydata", "r");
while( // read data from pipe is true )
// process data
std::getline() isn't part of C stdio, its part of C++. The getline with the signature int getline(char **, size_t *, FILE *) (i.e C stdio, thus the FILE * parameter) is not provided by MS in the windows C/C++ environment. Or at least it wasn't with VS 2017. It might have been added since then, but I don't think so.
I tried to do a basic calculation for testing the performance of different programming languages:
C/C++: (***3.05 s***)
int start = clock();
//<...>for (size_t i = 1; i < 100000000; i++)
result = sin((i * 25) / i * i);
//<...>int end = clock();//Now check what amount of ticks we have now. //To get the time, just subtract start from end, and divide by CLOCKS_PER_SEC.
std::cout << "it took " << end - start << "ticks std::endl;
C#: (***2.452 s***)
staticvoid Main(string args)
Stopwatch sw = new Stopwatch();
for (int i = 1; i < 100000000; i++)
result = Math.Sin((i * 25)/i * i);
And the same calculation in Python took 22.14 s to complete
Why is C# faster than C++?
Last Visit: 31-Dec-99 19:00 Last Update: 1-Feb-23 5:13