"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
In my program I'm using system("") command to add a variable into User variables using reg add. In the future I'll want to update the variable value to something else, but if the variable exists it will prompt the user to input Y/N to override it. Is there a way to automatically give the input instead of the user? I was thinking that maybe I could use system("y"), but it still waits for the input from the user, and then gives the error that y is not a command.
I can't use Windows.h to modify registry, so I want to find a solution to this. Maybe I'll need system("") for something else in the future that will have the same problem with having to input something.
Victor Nijegorodov wrote:
According to the reg add | Microsoft Docs you can add option /f that will cause the adding the registry entry without prompting for confirmation.
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.
Keep Calm and Carry On
Last Visit: 31-Dec-99 19:00 Last Update: 30-Jan-23 5:01