c

very basic c question

as we use pointers in the argument list of functions like void f(int *); this means that this function will receive a pointer to an integer but what does this means void f(int ***); and void f(int **=0) ...

Behavior of omp_get_max_threads in parallel regions

I compile this bit of code on Snow Leopard and linux and I get different results. On Snow leopard, the first call of omp_get_max_threads returns 2, which is my number of cores, while the second returns 1. On linux, both calls return 4, which is my number of cores. I think Linux has the correct behavior, am I right? Are both correct a...

Minimizing the amount of malloc() calls improves performance?

Consider two applications: one (num. 1) that invokes malloc() many times, and the other (num. 2) that invokes malloc() few times. Both applications allocate the same amount of memory (assume 100MB). For which application the next malloc() call will be faster, #1 or #2? In other words: Does malloc() have an index of allocated locations in...

2D vector modelling for game development

Making my Asteroids clone (in C) I've rather fallen in love with vector-based entities, but I've simply coded them in as x,y-point arrays. That's been fine for something like Asteroids, but what should I do if I want to make more complex 2D models? I note that there is an awful lot of 3D modelling software out there, as well as ample tu...

incompatible types when initializing type

I don't see why this error is coming up. Maybe someone else sees it. Here's the error. actor_plazma.c:92: error: incompatible types when initializing type ‘int (*)(struct VisObject *)’ using type ‘float’ actor_plazma.c:92: error: incompatible types when initializing type ‘void *’ using type ‘float’ make: *** [actor_plazma.lo] Error 1 ...

How to check if a dir exists in C

Hey guys, I'm relatively new to C, so forgive me if this is a stupid question, but how would I go about checking if a FILE is a directory? I have if (file == NULL) { fprintf(stderr, "%s: No such file\n", argv[1]); return 1; } and that checks if the node exists at all, but I want to know if it's a dir or a file. I've d...

How do I mmap a _particular_ region in memory?

I have a program. I want it to be able to mmap a particular region of memory over different runs. I have the source code of the program. C/C++ I control how the program is compiled. gcc I control how the program is linked. gcc I control how the program is run (Linux). I just want to have this particular region of memory, say 0xabcdab...

Is there a way to get battery level using unix c program

is there any way to create a daemon in unix that would monitor my battery level and notify me after the crtical level. and is there any way to identify a node that is joining and leaving a network using c ...

How to get the sub-string lying in between two sub-strings in C ?

I have a packet capture code that writes http payload into a file. Now i want to extract the URL information from these dumps. For each packet , the payload begins like this. GET /intl/en_com/images/logo_plain.png HTTP/1.1..Host: www.google.co.in..User-Agent: Mozilla/5.0 I would like to extract : the string between "GET" an...

mysqlclient library linkage problem

I am linking an application with mysqlclient library on 64-bit CentOS 5.4 and get a linkage error (cannot find -lmysqlclient). The library is in /usr/lib64/mysql/: una@localhost$ ll /usr/lib64/mysql/ total 9072 ... lrwxrwxrwx 1 root root 26 Jan 3 15:54 libmysqlclient_r.so -> libmysqlclient_r.so.15.0.0 lrwxrwxrwx 1 root root ...

How can I overwrite the first part of a struct in memory with a pointer?

I have a memory address of the start of a number of structs, but need to eliminate some from my output. I think the memory space would look something like +------------------+------------------+------------------+ | struct | struct | struct | | linux_dirent64{ | linux_dirent64{ | linux_dirent64{ | | ...

Simplest way to integrate python gui app with c console app

I have a c console app which converts a c file to a html file, the c file location is passed to the program as a command line argument.(the app is for the windows platform) What I would like to do is have a python gui app to allow the user to select a file and pass the location of the file to the c app for processing. I already know ho...

Sun RPC: transferring binary files

Hello everyone, I want to transfer binary files to remote server. I am using SUN/ONC RPC (rpcgen on Linux) for my code. I am using C. I have written code for server and client and it works for text files, but when I try to transfer binary files it says the file is corrupted after transfer. I am storing data chunks in character array o...

Can a java module call a c module ?

Just out of interest , is it possible to call a C module from a java module ? If so , how to do that ? ...

What does __inline__ mean ?

I am trying to learn C. Reading through some code I came across a line like this: __inline__ void () ... What does the __inline__ mean? And how does putting that word in front of a function make it different? ...

Cannot use send() to send .exe in c programming

I am building a server-client program with c and having some problen wtih sendina a whole file with send() and recv() function. I need to send the whole file with these but all these functions can do is send a string. The main problem is with sending the exe or other binary formet data. Should I use htons or htonl func? I dunno how to u...

C equivalent to fstream's peek

Hi, I know in C++, you're able to peek at the next character by using: in.peek();. How would I go about this when trying to "peek" at the next character of a file in C? ...

enum string comparison.

Hi, I need to compare an enum as a whole to one string, so the whole contents of the enum is checked. Wanted something like: NSString *colString = [[NSString aloc] initWithString:@"threeSilver"]; typedef enum { oneGreen, twoBlue, threeSilver }numbersAndColours; if (colString == numbersAndColours) { //Do cool stuff } But obviousl...

What could C/C++ "lose" if they defined a standard ABI?

The title says everything. I am talking about C/C++ specifically, because both consider this as "implementation issue". I think, defining a standard interface can ease building a module system on top of it, and many other good things. What could C/C++ "lose" if they defined a standard ABI? ...

Check if a double is evenly divisible by another double in C?

How can I check if a double x is evenly divisible by another double y in C? With integers I would just use modulo, but what would be the correct/best way to do it with doubles? I know floating point numbers carry with them imprecision, but I'm getting the double from standard input. Maybe I should not scan it as a double straight away b...