c

Mac OS X free C compiler

Is there a small, free C or C++ compiler for OS X, like TCC? Xcode is not small, or simple like TCC, AFAIK. I'm looking for something like a GCC binary file or TCC for OS X. ...

Can you explain this 'Hello world' program?

Hi, I just started learning C but I don't understand this part of the code. Can anyone explain each line of code and what it does. Thank you! Please just answer to what I said instead of saying (it should say in the book) Thank you. Hope you guys can help me. #include <stdio.h> void SayHello( void ); int main (int argc, const char * a...

How does this bitwise operation check for a power of 2?

I'm looking at some code which should be trivial -- but my math is failing me miserably here. Here's a condition that checks if a number if a power of 2 using the following: if((num != 1) && (num & (num - 1))) { /* make num pow of 2 */ } My question is, how does using a bitwise AND between num and num - 1 determine if a number is a p...

Variable Persistence Problem (C)

Hello: I'm making a domino game and when the user adds a domino to the left, the domino is added but when the function exits the domino added is GONE. FYI: fitxesJoc (Link List) contains the dominoes of the game and is a pointer passed to the function (so that it lasts all the game) opcionesCorrectas (Domino) contains the correct cho...

Segmentation fault when malloc/free appear in loop in C

Hi there, I have a program that basically looks like: typedef struct cpl_def { int A; int B; int OK; struct cpls *link; }cpls; int main(void) { int n1, n2; int num = 300; /* say */ int *a; ...

Variable Sized Arrays in C

I guess my question is whether the following is valid C int main(void) { int r = 3; int k[r]; return 0; } If so, would some one care to explain why it does not work in Microsoft's C compiler, but in GCC, and when it was added to the C standard. Thank you ...

Are pointers and arrays any different in C?

I'm writing a small C program to do some number crunching, and it needs to pass around arrays between functions. The functions should accept and return pointers, right? For example, this (I know it may not be the most efficient thing): int* reverse(int* l, int len) { int* reversed = malloc(sizeof(*reversed)*len); int i, j; ...

C Program to search n-th smallest element in array without sorting?

Hi all, I wanted to write a program to find the nth smallest element without using any sorting technique.. Can we implement it as a technique used in quick sort, which divides the problem into smaller sub-problems but how is my question.. Please provide some hint.. Thankx ...

Will this leak memory?

Hello. I made a small function to catenate strings and return the combined string. However since I assign memory to a third variable in the function, will the memory be freed when the function finishes or will it stay there, requiring me to free it later? and if I need to free it, what's the most stylish solution to do it? Here's the te...

C - Sending the contents of a matrix in one function to a matrix in another function

Good evening. How can I pass the contents of a char matrix in one function to another matrix of equal dimensions in another function? Many thanks in advance. ...

Print the Address a Pointer Contains in C

I want to do something that seems fairly simple... I get results but the problem is, I have no way to know if the results are correct. I'm working in C and I have two pointers; I want to print the contents of the pointer. I don't want to dereference the pointer to get the value pointed at, I just want the address that the pointer has st...

How do you call Python code from C code?

I want to extend a large C project with some new functionality, but I really want to write it in Python. Basically, I want to call Python code from C code. However, Python->C wrappers like SWIG allow for the OPPOSITE, that is writing C modules and calling C from Python. I'm considering an approach involving IPC or RPC (I don't mind ha...

Indications of possibly poor design

Hi I have a large code base. The whole code is in C. I feel that inappropriate attention has been given to design. What evidences should I look for in the C code base that are strong indicators of bad/poor design. And can some of theses indications be provided by some automated tools. Thanks Vivek Kumar ...

How to pass variable number of arguments to printf/sprintf

I have a class that holds an "error" function that will format some text. I want to accept a variable number of arguments and then format them using printf. Example: class MyClass { public: void Error(const char* format, ...); }; The Error method should take in the parameters, call printf/sprintf to format it and then do somethi...

Is it on the Stack or Heap?

I have some C code that is something of a puzzle. For a reason to do with this code, I'm wondering how I can tell if a struct object is ending up on the heap or stack? The objects are not being created with malloc or calloc. They start their life in the form of an array. For the purposes of this post, I'm going to call the struct Emp. ...

how to detect datacard connect and disconnect event on win32

Hi All, I have a data card, as soon as i insert the data card, i am getting the events by using wm_device_change event. But I also want to get event, when my data connect actually connects to out side world. I mean to say, as soon as we click on connect/disconnect button of data card,i want to get the event. exactly speaking wanted t...

stat systecall in linux returning error

I am using RHEL 4 i am using syscall stat as follows:- if (stat ("file",&stat_obj)){ if (errno == ENOENT){ printf("File not found"); }else{ printf("Unexpected error occured %d ",errno); } } sometimes i get error message as ""Unexpected error occured 0" That means i get error as "0" . i checked file permissions that are...

A question about printf arguments. C/C++.

Hello, We have the following code fragment: char tab[2][3] = {'1', '2', '\0', '3', '4', '\0'}; printf("%s\n", tab); And I don't understand why we don't get an error / warning in the call to printf. I DO get a warning but not an error, and the program runs fine. It prints '12'. printf is expecting an argument of type char *, i.e. a po...

Is it worth learning C to get a deeper understanding of OS'es and computers in general?

I'm currently working as a Actionscript 3 and Php developer. I started out learning Php then moved on to Actionscript 3 and now I'm learning Python. These 3 languages are high level languages which in none of them you have to worry about low level memory management and things like knowing which data type to use for different numbers. I...

fscanf reading problem

Hi, sorry, perhaps this is a stupid question. I have a file like this: 36 146 10 53 240 133 104 28 51 81 124 ... so I want to read the numbers from a program, so I do: .... some function ..... int i; unsigned char key[16]; FILE *fp; printf ("\n ------ \n"); // open filename fp = fopen("key.txt","a"); printf("...