c

C: assignment makes pointer from integer without a cast

Coming from a Java background I'm learning C, but I find those vague compiler error messages increasingly frustrating. Here's my code: /* * PURPOSE * Do case-insensetive string comparison. */ #include <stdio.h> #include <string.h> #include <ctype.h> int compareString(char cString1[], char cString2[]); char strToLower(char cStri...

Coding Practices which enable the compiler/optimizer to make a faster program.

Many years ago, C compilers were not particularly smart. As a workaround K&R invented the register keyword, to hint to the compiler, that maybe it would be a good idea to keep this variable in an internal register. They also made the tertiary operator to help generate better code. As time passed, the compilers matured. They became v...

how to convert from char* to char[] in c

hello, here is a code sample void() { char c[100]; scanf("%s",c); char c2[100]=c; } my problem is when i do this assignment an error says that i can assign char * "c" to char[] "c2"; how can i achieve this assignment? ...

C: passing arrays to another method properly

/* * PURPOSE * Search if a string contains a string and print it out from there */ #include <stdio.h> void searchHaystack(char cHaystack[], char cNeedle[]); void showResult(int iOffset, char cHaystack[]); int main() { // Declarations char cHaystack[50], cNeedle[50]; // Input puts("Haystack:"); gets(cHaystac...

Is it possible to catch touch events on the iPhone using pure C?

In iPhone applications you can catch touch events through the UIEvent and its associated set of UITouch instances, but this happens at Objective-C level. What I am looking for is a way to get this information at a lower level, in C code (no Objective-C involved), and in particular I'm thinking of Core Foundation data structures, similarl...

Lightweight open source software synth library on pure C (possibly C++). PCM. ?

Are there any portable open source libraries that support sample-based synthesis and encapsulate producing and mixing simple PCMs? I really need something minimalistic and decoupled from operating system audio output mechanisms. ...

help on sudoku solving

Can someone please help me understand this solution http://en.wikipedia.org/wiki/Algorithmics_of_Sudoku#Example_of_a_brute_force_Sudoku_solver_.28in_C.29 ...

Reading File Data Into a Linked List in C

I am trying to create a simple phonebook program that reads data from a file and stores the content into specific nodes in the list. It works fine if I use my addEntry function with static data, such as: addEntry("First", "Last", "555-555-5555"); If I try to read more than 1 entry from the file, each entry just appears to be whatever ...

How to get the name and value of attributes from xml when using libxml2 sax parser?

I got stuck on trying to detect the pair of name and value of the attributes in some general xmls by using libxml2 for parsing the api on iPhone application. For my project, the parsing speed is really important, so I decided to use libxml2 itself instead of using NSXMLParser. Now, as referring to XMLPerformance that is a sample of iPho...

More information on `({});` in C?

I've noticed that sometimes, C macros are written as something like this: #define foo(bar) ({ ++bar; }) After some experimentation, I've found that: ({}); will compile, but do nothing. (As expected.) Leaving the ; off will cause a syntax error. A side effect of this is ensuring that foo() looks like a function in your code. (Althoug...

k&r exercise confusion with bit-operations

The exercise is: Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged. My attempt at a solution is: #include <stdio.h> unsigned setbits(unsigned, int, int, unsigned); int main(void) { printf("%u\n", setbits(256, 4, 2, 255)); ...

passing pointers from C to C++ and vice versa

Is there any tips one can give me about passing pointers to structs, doubles, functions, ... from a C program to a C++ library and back? ...

Dispatch Table in C++

Suppose I have something like the following: class Point : geometry { ... Point(double x, double y) { } double distanceTo(Line) { } double distanceTo(Point) { } } class Line : geometry { ... Line(double x, double y, double slopex, double slopey) { } double distanceTo(Line) { } double distanceTo(Poi...

linux terminal animation - best way to delay printing of 'frame' (in C)

I'm working on a simple pong clone for the terminal and need a way to delay the printing of a 'frame'. I have a two dimensional array screen[ROWS][COLUMNS] and a function that prints the screen void printScreen() { int i = 0; int j; while(i < ROWS) { j = 0; while(j < COLUMNS) { printf("%c", ...

Reading an image file in C/C++

hi all, I need to read an image file in C/C++. It would be very great, if some one can post the code for me. I work on gray scale images and the images are JPEG. I would like to read the images into a 2D array which will make my work easy. Thanks in advance ...

Understanding the C function call prolog with __cdecl on windows

Compiling this simple function with MSVC2008, in Debug mode: int __cdecl sum(int a, int b) { return a + b; } I get the following disassembly listing: int __cdecl sum(int a, int b) { 004113B0 push ebp 004113B1 mov ebp,esp 004113B3 sub esp,0C0h 004113B9 push ebx 004113BA push esi 00...

any suggestion on clustered client server comm. approach?

Let's say i'm building a client server software. the main server connects to agents on different servers. the agents is a search client and each will return quite huge array of 64bit integers and finally the main server (parent) will sort it to produce finaly result. Which is better/faster approach, using a socket to get all the data...

using a portable int

gcc c99 MS2005/2008 I have started program that will be compiled on linux/windows. The program will be compiled on linux using gcc 4.4.1 c99. And on windows the compiler will be either MS 2005/2008. And this I cannot change. I am using SCons to create the build files. However, the reason I choose c99 as I can use the stdint.h so my i...

What specific examples are there of knowing C making you a better high level programmer?

I know about the existance of question such as this one and this one. Let me explain. Afet reading Joel's article Back to Basics and seeing many similar questions on SO, I've begun to wonder what are specific examples of situations where knowing stuff like C can make you a better high level programmer. What I want to know is if there a...

Is __int32 defined?

Hello, gcc c89 I am came across this code. typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef __int64 int64_t; typedef unsigned __int32 uint64_t; I am just wondering that is the __int32 I didn't think that was a type? Why the underscore? Does this mean I could do things like this? typedef __int32 myInt32; Many t...