c

Using a C function in Objective-C (for iPhone)

'lo all. I am a self-described admitted noob in iPhone programming (having a much longer perl & web background -- 30 years)...but took the plunge last week and bought a couple of good books. After cramming and reading well over 1000 pages -- and understanding it pretty well, I am well on my way to a good first Native iPhone app. My pro...

Getting 32 bit words out of 64-bit values in C/C++ and not worrying about endianness...

It's my understanding that in C/C++ bitwise operators are supposed to be endian independent and behave the way you expect. I want to make sure that I'm truly getting the most significant and least significant words out of a 64-bit value and not worry about endianness of the machine. Here's an example: uint64_t temp; uint32_t msw, lsw;...

C preprocessor in include header files

Hi All. I have a structure defined in a header file called data.h I am including data.h in myfile.c in the structure, I have part of the variables blocked off with #ifndef TEST int x; #endif and in myfile.c i have #ifdef TEST localx++; #else mystruct.x++; //<-compiler complains on this line when compiling #endif When I try to ...

Problem while printing a string

I'm writing a C Code in which my array of length 2 char contains String My But while printing it to the Screen using puts(). I'm getting this output My £■   0√" What is the reason for such codes ??? And if my array length is 2 then How can i get output of length 2+ ??? ...

Memcached rubygem + Rlibmemcached argument error with memcache_mget()

I am getting an exception when using Evan Weaver's Memcached gem (as Memcached::Rails.new) -> (http://github.com/fauna/memcached) and calling get_multi() ArgumentError: wrong # of arguments(2 for 4) from /usr/local/lib/ruby/gems/1.8/gems/memcache-auth-1.0.1/lib/memcached/memcached.rb:384:in `memcached_mget' from /usr/local/lib/ruby/gems...

Using pThreads, is it possible to write a function that can detect what thread it's being called from?

This is the usage case: Log(char* s); // prints out a log message Now: Log("hello world\n"); // called from Thread1 Desired output: Thread1: hello world Now: Log("hello world\n"); // called from Thread2 Desired output: Thread2: hello world I can have a map that maps thread pids to strings. What I need however, is a functio...

reading unknown number of integers from stdin (C)

I need to read an input file like : 1 19 20 41 23 2 41 52 43 3 90 91 941 4 512 5 6 51 61 each odd line is an integer each even line is unknown number of integers it is very easy in C++ while( cin >> k ){ ............ } Im not so used to C language so I couldnt make it in C. any ways to do it? ...

How to send Ctrl-C control character or terminal hangup message to child process?

I have a child process which runs in a pseudo terminal. The parent process does not run as root, but the child process does, through su or sudo. Because of this it is not possible to send a signal to the child process to force it to exit. I want to force it to exit by one of these means: emulating a Ctrl-C. emulating a terminal hangup....

Error while compiling GTK+ app with g_rename func

I'm trying to use g_rename and compiler gives me strange message "error: called object ‘rename’ is not a function" for line in code "if (g_rename(old_file_name, full_new_file_name) == -1)". I don't understand why. I'm compiling with command "cc -Wall -g pkg-config --cflags --libs gtk+-2.0 app.c -o app". Gcc version = gcc (Ubuntu 4.4....

Getting the exit status from inside an function registered with atexit()

Inside my atexit() registered function I would like to get the exit status (either the argument to exit(3) or what main() returned with). Is there any portable way of doing this? Is there any GNU libc specific way of doing it such as a global holding that value I can reference? ...

What's the best book to learn programming MySql from C/C++ ?

Not a generic introduction to MySql. I have one of those and also a PHP & MySql book. What's a good one to learn the C/C++ API? Or do I even need a book for that? Maybe it would be overkill? ...

How can I lock a file from a program started as a cron job on Linux?

I use fcntl in my codes to lock file and unlock to practice like mutex in windows... I start my app in linux manually, i got right result, with the app runs smoothly... but i was asked to make a bash script to start the app daily.... my script is cd myapppaht ./myapp however, i got [Bad file descriptor] when it try to lock a file pos...

How to correctly define char array

Hi all, Does anyone know how should ASF_OBJECT_GUID_TEST be defined to avoid compilation error in the line marked below, or where I can find more information about it? Thanks, Andre #define ASF_OBJECT_GUID_TEST {(char)0x75, (char)0xB2, (char)0x00} void testFunction(char * testChar) { } int main(int argc, char * argv[]) { char t...

Least Squares Regression in C/C++

How would one go about implementing least squares regression for factor analysis in C/C++? ...

Mac vs. Ubuntu for C/C++ development?

I'm looking to buy a personal machine for development and I'm deciding whether to go with a Mac or a PC (on which I'd run Ubuntu). My plans for the next year or so involve getting more heavily into C/C++ and networking than I currently am. Are there any differences I should be aware of between the two OSes as far as C/C++ system librar...

Documentation for CMX ColdFire USB-Lite stack

This is my first embedded project, so bear with my ignorance. I've been asked to implement Remote NDIS over USB, using the ColdFire USB-Lite stack by CMX. I've been searching for a long time now, and can't find any clear documentation for this stack. It comes with some woefully documented sample code and the only useful resource I've b...

Extern structure in C...

How to extern structure in c language. So that I can use a structure into b. ...

Storing/Comparing u_char passed to function

I have a simple function that passes a variable "var" as a u_char array. I have no difficulty printing that array. printf("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", var[0], var [1], var[2], var[3], var[4], var[5]); Prints the mac address out just the way I like it. I cannot for the life of me figure out the proper way to store this...

What are the pros and cons of using Matrices, Euler Angles, and or Quaternions for rotation representation?

Matrices and Euler angles can suffer from Gimbal lock but what are some other arguments for using one over the other? What do you think DirectX favors? What do you use in daily C++/C/DirectX programming? ...

Purpose of #ifndef FILENAME....#endif in header file

I know it to prevent multiple inclusion of header file. But suppose I ensure that I will include this file in only one .cpp file only once. Are there still scenarios in which I would require this safe-guard? ...