c

An array of structures within a structure - what's the pointer type?

I have the following declaration in a file that gets generated by a perl script ( during compilation ): struct _gamedata { short res_count; struct { void * resptr; short id; short type; } res_table[3]; } _gamecoderes = { 3, { { &char_resource_ID_RES_welcome_object_ID,1002, 1001 }, { &blah_resource_ID_RES_another_object...

Problem in accepting connection from client (socket programming) in Visual C++

I have written a simple single threaded client server application in Visual C++. When I run my server I wait for some time that it accepts some request from the client. When I connect the client to the server. The log message on the client reports 14 bytes are send and there is no message on the server. I have written a print statement ...

I want to learn Objective-c, but...

...I am not sure which book to go with. I came to conclusion and it's between those two: [Programming in Objective-C 2.0] vs. [Learn Objective-C on the Mac]. My programming experience/skill is fairly strict, as I just know a little C. I know some loops (if, if-else, while, for, do, case) and how algorithm work. That's pretty much it, I...

Library for audio resampling

In an embedded (Windows CE) C++ project, I have to resample an arbitrary sample-rate down (or up) to 44100 Hz. Is there a free and portable C/C++ library for audio resampling? ...

Weirdest segmentation fault ever.

Ok basically I'm writing a program that takes in two directories and processes them based on what options are supplied. Thing is it's giving me segmentation errors at times when I don't see a problem. The code that is causing the problem is the following: EDIT: Update the code to include my entire source file #include <unistd.h> #inclu...

ivars when mixing C and Objective-C

I'm writing an Objective-C wrapper for a C library and having problems accessing the references of my ivars. The C library requires that I specify a function pointer that handles events, I specify it during the initialization of my Objective-C class. - (id) init { [super init]; RegisterClient( return self; } The C librar...

C Program terminating with -1 (0xFFFFFFFF), seemingly no reason?

#include <stdio.h> typedef struct pduct {char name[20]; int price; int stock;} PRODUCT; void init(PRODUCT * product) { printf("What is the name of the product: "); fgets(product->name, 20, stdin); printf("DEBUG: Did it get written...: %s", product->name); printf("What is th...

Arithmetic Bit-shift on a signed integer

Hi ! I am trying to figure out how exactly arithmetic bit-shift operators work in C, and how it will effect signed 32 bit integer. To make things simple, lets say we work within one byte(8 bits) - x = 1101.0101 MSB[ 1101.0101 ]LSB Reading other posts on Stack & some websites, I found that: << will shit toward MSB(to the left, in my...

C free char* allocated on heap

Is there a memory leak in the following code example as I have allocated memory on the heap for name which hasn't been freed? If I add free(person->name); before the free(person); line then I get a runtime error in VS "CRT detected that the application wrote to memory after end of heap buffer". header.h: #ifndef HEADER #define HEADER ...

Write the array notation as pointer notation.

The question is &str[2], if I write str+2 then it would give the address and its logical but where did I used pointer notation in it? Should I prefer writing &(*(str+2))? ...

problem in accepting connection from client (socket programming) in VC++.net

Hi Jerry, I have corrected the above syntax error i am having the same problem. nothings appears on my end can u tell me how u are executing the code. i am executing it by simple running first the server and then client in visual stdio 2005. ...

Is there any way the size of the pointer can be changed from 2 bytes?

Can we anyhow change the size of the pointer from 2 bytes so it can occupy more than 2 bytes? ...

C macro for printf

Is it possible to write a Macro (using token concatenation) that returns fmt for printf ? Eg. #define STR_FMT(x) ...code-here... STR_FMT(10) expands to "%10s" STR_FMT(15) expands to "%15s" ... etc. So that I can use this macro inside a printf: printf(STR_FMT(10), "*"); ...

strcspn() stopping at a period

Hi. I'm writing a function that should parse a string containing a description of a dice roll, for instance "2*1d8+2". I extract the four values OK when they are integers, but I want to be able to use floats as well for the multiplier and the addition at the end. Things get nasty when I try to parse such a string: "1.8*1d8+2.5". I have ...

XCode - Import Sedna libs

What you I have to do in XCode to include the Sedna (Native XML DB) libs? The files are: /usr/local/sedna/driver/c/libsedna.h /usr/local/sedna/driver/c/libsedna.dylib I try to puts these path (/usr/local/sedna/driver/c) on "Search Paths"->"User Header Search Paths" and nothing. Code: #include <stdio.h> #include "libsedna.h" struct...

Wrapping a C library in a C++ class with type conversion

Hello everyone, I'm slowly learning to be a better C++ programmer and I'm currently debating the best way to implement a wrapper for a C library. The library is a wrapper around a compressed file format that can store tags of various types (char *, char, double, float, int32_t). The types are stored as uint8_t* and there are a bunch o...

smallest value of hash() function?

in python (3), what is the smallest value that hash(x) can return? i want to use hashes to give a quick 'fingerprint' to database values (basically making it easy to see whether two longish, similar texts are actually equal or not), and want to get rid of negative numbers (for simplicity), so i thought i'd just add the smallest possibl...

C: setting an array member of a struct through a pointer

I have a struct with an array as a member, and am trying to set that array using arrow syntax. What I have: typedef float Foo[3]; typedef struct { Foo foo; } Bar; Bar* f() { Bar* bar = malloc(sizeof(Bar)); bar->foo = {1.0, 1.0, 1.0}; return bar; } gcc says: error: expected expression before '{' token on the line bar->foo ...

HTTP Server Programming

Hello all, I'm attempting to write my own http 1.1 server, just for fun and learning about more about HTTP, sockets, and threading. I've gotten a good start i think with only delivering static pages (using c, which I would prefer to stay in for the time being). I have a test page I wrote a while ago and deliver it's ~50 files in 124ms...

Incompatible Pointer Type Error

Hey everyone, I am getting a compile error in my code, and I cannot figure out what to do. Here's the block: #include <stdio.h> #include <string.h> /* * Function to return index at which team ID input is stored */ int getIndex(char* id, char* idList[][50]) { int k; for (k=0; k<50; k++) { if (strcmp(id,idList[k])==0...