I have this code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
// Define the function to be called when ctrl-c (SIGINT) signal is sent to process
void
signal_callback_handler(int signum)
{
printf("Caught signal %d\n",signum);
// Cleanup and close up stuff here
// Terminate program
exit(signum);
}
int main()
...
Possible Duplicate:
The Definitive C++ Book Guide and List
I have finally got round to reading K&R, and it is by far the best (programming) book I ever expect to read. It is compact and lucid. It is nectar for my logic centre. The examples are concise, and useful. Moreover they do not contain the words 'boss' and 'employ...
I'm using dirname from libgen.h to get the directory path from a filename's path.
This is it's signature:
char * dirname (char *path)
When compiling on a 32 bit machine or using -m32 with gcc, it all works fine.
My code looks like this:
char* path = "/path/to/my/file.txt";
char* path_cpy = strdup(path);
const char* dir = (const cha...
const char* a;
how do I make sure that string 'a' is null terminated? when a = "abcd" and I do sizeof(a), I get 4. Does that mean its not null-terminated? if it were, I would have gotten 5 ?
...
int mystery( const char *s1, const char *s2 ) {
for( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ ) {
if( *s1 != *s2 ) {
return 0;
} //end if
} //end for
return 1;
}
I know it has typing errors but this is exactly how it was.
...
I am only having this problem when running my program on a Mac; linux 64 and 32 bit are fine but on mac I get a bunch of:
*** malloc[437]: error for object 0xbfffe970:
Non-aligned pointer being freed (2)
towards the end of execution of my program where I am freeing a bunch of pointers in a data structure. Code to long to be posted bu...
I'm following a guide to learn curses, and all of the C code within prototypes functions before main(), then defines them afterward. In my C++ learnings, I had heard about function prototyping but never done it, and as far as I know it doesn't make too much of a difference on how the code is compiled. Is it a programmer's personal choice...
Here's a good one to reflect on:
http://en.wikipedia.org/wiki/Kakuro
I'm attempting to make a solver for this game. The paperwork is done (reading an initial file with a variable number of columns and rows. It's assumed the input file follows the rules of the game so the game is always solvable. Take your time to read the game rules.
...
Right when I am at fflush(stdout) and I break there in GDB, can I know what is there in stdout before I actually print it?
How can I know what is there in stdout at any point in time?
...
If you are in a 3rd nested loop in PHP, you can do break 3; and break all loops up 3 levels.
break seems to work in C. But if I do break 3 I get a syntax error. I guess it doesn't support it.
What is the best way to break multiple loops? Should I set a flag which is checked up the loops - and breaks if it is set?
Is there anything mor...
I'm working on a prodgect in which I need a huge number, 1 billion digits. I'm writing in c, though I'll take answers from objective-c.
Also, I'm wondering about this function/data type I found: Biginteger.
I would like to know what language people use this in and if it will help my problem.
Please respond,
Frederick
...
I am trying to extract level data from a PCM audio file using core audio. I have gotten as far as (I believe) getting the raw data into a byte array (UInt8) but it is 16 bit PCM data and I am having trouble reading the data out. The input is from the iPhone microphone, which I have set as:
[recordSetting setValue:[NSNumber numberWithInt...
Hi all,
I want to create a ruby extension that uses c. But when I compile it with gcc, I am getting this error:
gcc rubyext.c -orubyext -I /usr/local/include/ruby-1.9.1/
In file included from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/ruby.h:25:25: error: ruby/config.h: No such file or directory
In file included from rubyext.c:1:...
I want to develop one PPPoe-like server, so I can create a virtual connecting among server and client. Is there any opensource project for reference ? Thanks
...
Hi. I'm practising with C, writing simple programs. The little program below should just get 3 numbers from the user and multiplicate them. My problem is that i'm a bit confused about the variable type i must use. I want the program to take any number such as 5, 5.673434, 99.123 and so, calculate with them and print out a rounded flo...
I'm trying to do a Project Euler question.
I'm looking for the sum of all prime numbers under 2,000,000.
This is what I have...
int main(int argc, char *argv[]) {
unsigned long int sum = 0;
for (unsigned long int i = 0; i < 2000000; i++) {
if (isPrime(i)) {
sum += i;
}
}
printf("sum =>...
I'm writing an immutable linked list class in C, but one method is mysteriously segfaulting. The code is intended to be roughly equivalent to this:
class PList(object):
def __init__(self, first, rest=None):
self.first = first
self.rest = rest
def cons(self, item):
return PList(item, self)
Here is my c...
I am new to programming, and even newer to Linux. I was told that Linux is the best OS to learning to program as it lets a programmer interface closely with the machine architecture. I heard a lot about the GNU tool-chain and that it provides the best programming environment on Linux so I decided I won't use an IDE and put in as much tim...
I am facing problem of memory leak and other MoviePlayer new initiation as my MoviePlayer doesn't respond to function, in which I am releasing that player on my done button.
(void) playMovieAtURL
{
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]]...
Hello, I happen to have several functions which access different arguments of the program through the argv[] array. Right now, those functions are nested inside the main() function because of a language extension the compiler provides to allow such structures.
I would like to get rid of the nested functions so that interoperability is p...