c

Why is abs(0x80000000) == 0x80000000?

I just started reading Hacker's Delight and it defines abs(-231) as -231. Why is that? I tried printf("%x", abs(0x80000000)) on a few different systems and I get back 0x80000000 on all of them. ...

how can I create macro definitions for the lines commented in the code.

#include <stdio.h> //Here use a macro definition that assigns a value to SIZE (for example 5) int main() { int i; int array[SIZE]; int sum=0; for(i=0; i<SIZE; i++) { //Here use a macro definition named as CALCSUM to make the //following addition operation for the array ...

C++ -- return x,y; What is the point?

Hello, I have been programming in C and C++ for a few years and now I'm just now taking a college course in it and our book had a function like this for an example int foo(){ int x=0; int y=20; return x,y; //y is always returned } I have never seen such syntax. In fact, I have never seen the , operator used outside of parameter ...

Quick question: explain this typedef

typedef int py_var_t (void *); it is used as: py_var_t *somesymbol ...

How to change/show permissions in C

Hi! I am new to C programming and I'd like to implement chmod command on files of a dir and subdir. How can I change/show permissions with a C code? Could someone help with a example? I would appreciate if anyone can provide me a code. ...

Get country tld

Hello, How do I programmatically get the system country tld. In the registry there's a key called sCountry which has the country's name, but in the system language, eg. If the user has the Spanish version sCountry would be Espana, German version would be Deutschland, etc. ...

C, reading multiple numbers from single input line (scanf?)

Hi, I'm writing an app in pure C which expects two line at input: first one, which tells how big an array of int will be, and the second, which contains values, separated by space. So, for the following input 5 1 2 3 4 99 I need to create an array containing {1,2,3,4,99} Now, my question is - what is the fastest (yet easy ;)) way to do ...

How can I remove the head of a main function?

I am trying to move some code from a separate binary and have it inside my main program. Unfortunately I can't mimic the initialization variables for the main function. How can I create argc and argv by hand? Can someone give me some example assignments. since it looks like this: int main(int argc, char *argv[]) I figured I could a...

Incompatible pointer type

Hello. I have the function with following signature: void box_sort(int**, int, int) and variable of following type: int boxes[MAX_BOXES][MAX_DIMENSIONALITY+1] When I am calling the function box_sort(boxes, a, b) GCC gives me two warnings: 103.c:79: warning: passing argument 1 of ‘box_sort’ from incompatible pointer type (string...

C Socket Programming, problems with select() and fd_set

Hello I'm learning my way about socket programming in C (referring to Beej). Here is a simple multi-user chat server i'm trying to implement: http://pastebin.com/gDzd0WqP On runtime, it gives Bus Error. It's coming from the lines 68-78. Help me trace the source of the problem? in fact, WHY is my code even REACHING that particular re...

Triggering Signal Handler For I/O.

Using C on Linux, how would I go about triggering a signal handler every time I write data to a buffer using the write() function. The handler will be reading all data written to the buffer at the time of execution. ...

how can i sort one array with 2 child using fork() in c

example some array {2,8,9,10,21,32,1,6,3...} first child take (data size / 2) and sort second chile take (data size / 2) and sort after combine 2 child data and give us a sorted full data, is it possible with some algorithms? ...

find out what functions a static C library has

hi, I have a static C library (say mylib.a) and I was wondering if it's possible to find out what functions are implemented inside that file. I don't have a corresponding header file. what I need is like the equivalent of javap for Java. ...

Problem with semaphores and sem_wait()

I have a queue structure that is being used by several pthreads. The threads are supposed to dequeue from the queue if it's not empty and then do their business. I initially had this set up as a while loop where the threads checked whether the queue was empty using a mutex_lock. Unfortunately this slowed my program down to a crawl. I t...

Should I enforce realloc check if the new block size is smaller than the initial?

Can realloc fail in this case? int *a = NULL; a = calloc(100, sizeof(*a)); printf("1.ptr: %d\n", a); a = realloc(a, 50 * sizeof(*a)); printf("2.ptr: %d\n", a); if(a == NULL){ printf("Is it possible?\n"); } return (0); } The output in my case is: 1.ptr: 4072560 2.ptr: 4072560 So 'a' points to the same adress. So should I en...

program that writes the even and odd numbers

I was writting a program that can read a set of numbers file called dog.txt; and also writes to two file separating odd and even. i was able to compile my program however, the output expected is not the same which was supposed to be even numbers in one file called EVEN, odd numbers in file odd. #include <stdio.h> #include <stdlib.h> in...

Linux Bluetooth programming

I am making a desktop application to connect with an embedded device. I was going to use Windows but due to lack of proper examples and documentation I decided to go with Linux bluez development. Can someone suggest a good resource to go about programming for bluez. I found a MIT documentation but that was about it. ...

array iteration strstr in c

I was wondering if it's safe to do the following iteration to find the first occurrence of str within the array or if there is a better way. Thanks #include <stdio.h> #include <string.h> const char * list[] = {"One","Two","Three","Four","Five"}; char *c(char * str) { int i; for (i = 0; i < 5; i++) { if (strstr(str, li...

Setting enum values to 4-byte strings - why?

I saw code similar to this in the Mac OS SDK: enum { kAudioFileStreamProperty_ReadyToProducePackets = 'redy', kAudioFileStreamProperty_FileFormat = 'ffmt', kAudioFileStreamProperty_DataFormat = 'dfmt', kAudioFileStreamProperty_FormatList = 'flst', kAudioFileStreamProperty_Magic...

How to detect what platform an application is running on in C

Hi, I was wondering how you could detect what platform a program is running on, I have an application and need it to go to a certain folder depending on whether it is on a Linux or Mac machine. Thanks! ...