c

Initializing struct, using an array

I have a couple of array's: const string a_strs[] = {"cr=1", "ag=2", "gnd=U", "prl=12", "av=123", "sz=345", "rc=6", "pc=12345"}; const string b_strs[] = {"cr=2", "sz=345", "ag=10", "gnd=M", "prl=11", "rc=6", "cp=34", "cv=54", "av=654", "ct=77", "pc=12345"}; which i then need to parse out for '=' and then put the values in the struct. ...

Anyone know how to use WMI with C instead of C++ ?

I'd hate to have to relearn C++ just for this! Any libraries/URLs would be great and yes, Google didn't help much here :-( This is for an upcoming project in which my product (Java based) would provide support for Microsoft's Hyper-V virtualization platform. Unlike VMware, which provides a Web-service, the Hyper-V APIs are mere extensi...

Parsing C++ preprocessor #if statements

I have a C/C++ source file with conditional compilation. Before I ship it to customers I want to remove most of the #if statements, so that my customers do not need to worry about passing the right -D options to the compiler. I have this implemented and working in Python, but it only handles #ifdef and #ifndef statements properly. I n...

why does this happen (see image)?

Why does the following have the effect it does - it prints a terminal full of random characters and then exits leaving a command prompt that produces garbage when you type in it. (I tried it because I thought it would produce a seg fault). http://s4.tinypic.com/r9qxbt.jpg #include <stdio.h> int main(){ char* s = "lololololololol";...

Java - C-Like Fork?

Is it possible to do a "C like" fork in java, using an new independent jvm process ? How? ...

How to safely escape a string from C++

I'm writing a simple program to browse the local network and pass on filenames to mplayer using "system". However, sometimes filenames contain spaces or quotes. Obviously I could write my own function to escape those, but I'm not sure exactly what characters do or do not need escaping. Is there a function available in the CRT or somewhe...

Is close/fclose on stdin guaranteed to be correct?

It seems as though the following calls do what you'd expect (close the stream and not allow any further input - anything waiting for input on the stream returns error), but is it guaranteed to be correct across all compilers/platforms? close(fileno(stdin)); fclose(stdin); ...

Variable declaration placement in C

I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement rules for C89/ANSI C? The following code compiles successfully with "gcc -std=c89" and "gcc -ansi": #include <stdio.h> int main() { int i;...

How can I pass a pointer to an array using p/invoke in C#?

Example C API signature: void Func(unsigned char* bytes); In C, when I want to pass a pointer to an array, I can do: unsigned char* bytes = new unsigned char[1000]; Func(bytes); // call How do I translate the above API to P/Invoke such that I can pass a pointer to C# byte array? ...

get VC debugger to show more frames in a stack overflow

I was remote debugging a stack overflow from a recursive function. The Visual Studio IDE only showed the first 1,000 frames (all the same function), but I needed to go up further too see what the cause was. Does anybody know how to get VS to 'move up' in a stack listing? Thanks. ...

Solution for "dereferencing `void *' pointer" warning in struct in C?

Hi, I was trying to create a pseudo super struct to print array of structs. My basic structures are as follows. /* Type 10 Count */ typedef struct _T10CNT { int _cnt[20]; } T10CNT; ... /* Type 20 Count */ typedef struct _T20CNT { long _cnt[20]; } T20CNT; ... I created the below struct to print the array of above mentioned ...

Using strtok with a string argument (instead of char*)?

I have a string that I would like to tokenize. But the strtok() function requires my string to be a char*. How can I do this quickly? token = strtok(str.c_str(), " "); fails because it turns it into a const char*, not a char* ...

Why this union's size is 2 with bitfields?

I am working on turbo C on windows where char takes one byte.Now my problem is with the below union. union a { unsigned char c:2; }b; void main() { printf("%d",sizeof(b)); \\or even sizeof(union a) } This program is printing output as 2 where as union should be taking only 1 byte. Why is it so? for struct it is fine giving 1 byte bu...

Does this code remove a file extension?

This isn't my code; I am trying to figure out what exactly this does. This is a part of a big, ancient system written in C (actually it was written 4 years ago, but most likely written by a late 80s programmer mentality). Part of the code: char DestFile[256]; char DestFile2[256]; //This part is just to show an example strcpy(DestFile, ...

How do I redirect terminal output from a C program to System.out with JNI?

I am invoking a C library via JNI that prints to stdout. How can I redirect this output to System.out? ...

How can I find out which library is home to a given object?

I'm programming in FORTRAN and C on an SGI running Irix 6.5, but this should be applicable to all Unix-like systems. How do I find which library I need to link to my program when I get an "unresolved text symbol" link error? Here's an example of what I'm seeing from the linker: ld32: ERROR 33 Unresolved text symbol "ortho2_" -- first...

Overriding functionality with modules in Linux kernel

Without getting into the details of why, I'm looking for a clean (as possible) way to replace kernel functions and system calls from a loadable module. My initial idea was to write some code to override some functions, which would take the original function (perhaps, if possible, call the function), and then add some of my own code. Th...

Http status code with libcurl?

How do I get the HTTP status code (eg 200 or 500) after calling curl_easy_perform? ...

Prevent C preprocessor to do a specific macro subsitution

How can I tell the preprocessor not to replace a specific macro? The specific problem is the following: Windows header files define the GetMessage macro. My C++ header files with my API have a GetMessage method. I do not want to rename my method. But when using the API on Windows, including windows.h replaces my GetMessage method call ...

What is the best way to return an error from a function when I'm already returning a value?

I wrote a function in C that converts a string to an integer and returns the integer. When I call the function I also want it to let me know if the string is not a valid number. In the past I returned -1 when this error occurred, because I didn't need to convert strings to negative numbers. But now I want it to convert strings to negativ...