c

Programmatically insert and remove kernel modules in C

Is there anyway to do "insmod" and "rmmod" from C/C++ code? Other than running system(...), is there a Kernel API that will allow me to do this? ...

Argc/Argv C Problems

Hey all, If I have the following code: main(int argc, char *argv[]){ char serveradd[20]; strcpy(serveradd, argv[1]); int port = atoi(argv[2]); printf("%s %d \n", serveradd, port); The first two arguments to the command line are printed. However, if I do this: char serveradd[20]; strcpy(serveradd, argv[1]); int port = atoi(arg...

C++ packing a typedef enum

typedef enum BeNeLux { BELGIUM, NETHERLANDS, LUXEMBURG } _ASSOCIATIONS_ BeNeLux; When I try to compile this with C++ Compiler, I am getting errors, but it seems to work fine with a C compiler. So here's the question. Is it possible to pack an enum in C++, or can someone see why I would get the error? The error is: "semico...

Finding N contiguous zero bits in an integer to the left of the MSB position of another integer

The problem is: given an integer val1 find the position of the highest bit set (Most Significant Bit) then, given a second integer val2 find a contiguous region of unset bits to the left of the position yielded from the first integer. width specifies the minimum number of unset bits that must be found in contiguity (ie width zeros withou...

How can you track mouse input using the fewest libraries in c.

I'm not sure where to look to find this information, but I'd like to know how to get mouse input (or any hid input) using the fewest non standard libraries in c. Basically, is there an stdio equivalent for mouse (and other input) input in c? Or is there a library that is minimal and cross compatible on multiple platforms. Just being able...

C newbie malloc question

Why doesn't this print 5? void writeValue(int* value) { value = malloc(sizeof(int)); *value = 5; } int main(int argc, char * argv) { int* value = NULL; writeValue(value); printf("value = %d\n", *value); // error trying to access 0x00000000 } and how can I modify this so it would work while still using a pointer a...

Function callers in C?

So I was wondering how they work. To explain what I mean by a "function caller" a good example of what I mean would be glutTimerFunc, it is able to take in a function as a parameter and call it even with it not knowing it is declared. How is it doing this? ...

C - Call a function

Hello. I want to get a value from a function in other function i think i have to call a function in other function, then call it on main, but how? void funcA(PEOPLE people[], int *total) { FILE *fp; char line[100]; fp = fopen("example.txt", "r"); if (fp == NULL) { exit(1); } else { fgets(line, 100, fp); ...

From float to mpz_t

I am using GMP in C. Is it possible to set a mpz_t to the value of a float? ...

Recommendations for 'C' Project Architecture Guidelines?

Now that I got my head wrapped around the 'C' language to a point where I feel proficient enough to write clean code, I'd like to focus my attention on project architecture guidelines. I'm looking for a good resource that coves the following topics: How to create an interface that promotes code maintainability and is extensible for fu...

Finding the centroid of a polygon?

I have tried: for each vertex, add to total, divide by number of verities to get center. I'v also tried: Find the topmost, bottommost -> get midpoint... find leftmost, rightmost, find midpoint. Both of these did not return the perfect center because I'm relying on the center to scale a polygon. I want to scale my polygons so I may put...

What primitive data type is time_t?

I do not know the data type of time_t. Is it a float double or something else? Because if I want to display it I need the tag that corresponds with it for printf. I can handle the rest from there for displaying time_t but I need to know the data type that corresponds with it. ...

printf field width : bytes or chars?

The printf/fprintf/sprintf family supports a width field in its format specifier. I have a doubt for the case of (non-wide) char arrays arguments: Is the width field supposed to mean bytes or characters? What is the (correct-de facto) behaviour if the char array corresponds to (say) a raw UTF-8 string? (I know that normally I should...

Running out of memory.. How?

I'm attempting to write a solver for a particular puzzle. It tries to find a solution by trying every possible move one at a time until it finds a solution. The first version tried to solve it depth-first by continually trying moves until it failed, then backtracking, but this turned out to be too slow. I have rewritten it to be breadth-...

How do I programatically pop up a console from winMain in C?

int WINAPI WinMain (HINSTANCE p1, HINSTANCE p2, LPSTR p3, int p4) { } I want a console to pop up when I click a button,what's the proper way to do it? UPDATE How do I output text to that console? ...

How do I stop the capture using winpcap?

/* start the capture */ pcap_loop(adhandle, 0, packet_handler, NULL); The above starts the capture,but I don't find a way to stop the capture except exit the programe... ...

MPFR Rounding 0.9999 to 1?

I'm attempting to store the value 0.9999 into an mpfr_t variable using the mpfr_set_str() function But 0.9999 is rounded to 1 (or some other value != 0.9999) during storage, no matter the round value (GMP_RNDD, GMP_RNDU, GMP_RNDN, GMP_RNDZ) So what's the best method to store 0.9999 in an mpfr_t variable using mpfr_set_str()? Is it poss...

Is there a function akin to fprintf but only returns the result of formated string in C?

fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf); I don't want to output anything via fprintf,but only the result of "Error in pcap_findalldevs: %s\n", errbuf,what's the function for that? ...

removing subset transactions form file

I have a file containing data as follows 10 20 30 40 70 20 30 70 30 40 10 20 29 70 80 90 20 30 40 40 45 65 10 20 80 45 65 20 I want to remove all subset transaction from this file. output file should be like follows 10 20 30 40 70 29 70 80 90 20 30 40 40 45 65 10 20 80 Where records like 20 30 70 30 40 10 20 45 65 ...

basename() returning int?

Probably something stupid I'm missing but, why am I getting this warning? static void foo(char *path) { char *bname; char *path2 = strdup(path); bname = basename(path2); (line with basename() call): warning: assignment makes pointer from integer without a cast Indeed, if I change to this, the warning goes away: bname...