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...
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...
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?
...
/*
* 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...
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...
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.
...
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
...
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 ...
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...
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...
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));
...
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?
...
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...
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", ...
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
...
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...
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...
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...
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...
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...