This is a few questions compiled into one post.
1) What would be the best way to tell if a USB mass storage device is plugged in.
2) What is the best way to write data to a USB drive
3) Can you treat the memory on a usb drive as you would in regular memory..
(Could I use like malloc and or write directly two it with values/ and or ...
RegOpenKeyEx()
I want to printf("Success") or printf("Failure") depending on if the function fails or succeeds
How would I do such a conditional while keeping it neat and legible?
I am wanting to stay away from this :
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"HUGE LONG KYEY STRUCTURE HERE",0,KEY_SET_VALUE) != 0 )
{
//CODE
}
...
I have a daemon that reads a configuration file in order to know where to write something. In the configuration file, a line like this exists:
output = /tmp/foo/%d/%s/output
Or, it may look like this:
output = /tmp/foo/%s/output/%d
... or simply like this:
output = /tmp/foo/%s/output
... or finally:
output = /tmp/output
I hav...
How can I simulate these calls inside a program?
Like say I want to find all the active connections. So I want to use netstat -a
How could I use that without having to literally having a window open?
...
I'm writing a small kernel for my programs in C.
This is not (at the moment) an OS kernel, it's merely a way for me to keep track of input and output in programs without relying on external source (i.e. stdio.h). You might ask me why I'd ever want to do this; it's just so I know how this works, and so that I have more, and more (end goa...
Hi, I'm wondering if it's possible to use inline assembly with the intel syntax in c, using tcc (not gcc)
thanks
...
How do you do nonblocking console IO on Linux/OS X in C?
...
Hey all. I'm working on a project for school where I need to pass a few parameters by reference through multiple functions. I understand how I can pass by reference from where the variables are declared to another function, like this:
main() {
int x = 0;
int y = 0;
int z = 0;
foo_function(&x, &y, &z);
}
int foo_function(int* x, int* ...
I just got some C code that uses extern "C" to declare external functions like this:
extern "C" void func();
Is this valid C? I'm getting an error at this line, but I'm not sure if it's because of this or something else.
...
On OS X privileged operations are done through AuthorizationExecuteWithPrivileges() around which Apple published two recommendations:
The old MoreAuth using setuid helper tools.
The current BetterAuthorizationSample littering the system with launchd files.
I don't know any applications using the latter...
...
Should i use this form of switch statement:
switch(msg)
{
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, (LPWCH)szFileName, MAX_PATH);
MessageBox(hwnd, (LPCWSTR)szFileName, L"This program is:", MB_OK | MB_...
consider the program below
char str[5];
strcpy(str,"Hello12345678");
printf("%s",str);
When run this program gives segmentation fault.
But when strcpy is replaced with following, program runs fine.
strcpy(str,"Hello1234567");
So question is it should crash when trying to copy to str any other string of more than 5 char...
Hi,
Can I expect that any "data" pointer in user space programs lies in a safe distance from the addresses 0 and 0xffffffff..., so that I can safely add a small offset to the pointer without checking for an overflow? What is the largest positive n for which I can safely assume that p + n doesn't overflow when p is a char pointer into a ...
I have a C function that takes a function pointer as argument, it's a destructor that I'll call at the end of my program. Here is the prototype of my function :
int store_dest(void (*routine)(void *));
I want to store this function pointer into a structure with some other infos. In order to have a nice struct, I want to have a typedef...
I have one costly function that gets called many times and there is a very limited set of possible values for the parameter.
Function return code depends only on arguments so the obvious way to speed things up is to keep a static cache within the function for possible arguments and corresponding return codes, so for every combination of ...
I was wondering about little differences between declaration of function prototypes in headers and in .c files. I have a header with some prototype functions and a some .c files with real implementation of these functions. I made some changes in the header, only added "__restrict" qualifier (recognized by gcc). My question is do I have t...
I have several structs bound with Data_Wrap_Struct to ruby objects and I also supplied mark() and free() functions.
When I manually start the GC or just wait until it jumps in my ruby objects are killed.
Nothing new so far.
The strange thing is: When I try to protect these objects with rb_gc_register_address() nothing happens - my o...
char hello[] = "hello"; #C
hello = ['h', 'e', 'l', 'l', 'o'] #Ruby
If I output the class of hello[0] in Ruby, it says "String". This is because single quoted Strings exist in Ruby and there does not seem to be the notion of a char type. The other day I said to my coworker that he had an array of characters and he said "no I don't, I ha...
The problem I am having is that when say for instance the user enters 7, then the display shows:
0 11 2 3 5 8 13 21 child ends.
I cannot seem to figure out how to fix the 11 and why is it displaying that many numbers in the sequence! Can anyone help?
The number of the sequence will be provided in the command line. For example, if 5 i...
How, in C, can I detect whether a program is connecting to itself.
For example, I've set up a listener on port 1234, then I set up another socket to connect to an arbitrary address on port 1234. I want to detect whether I'm connecting to my own program. Is there any way?
Thanks,
Dave
...