c

Pointers and cstring beginner troubles

I have a problem with the function replace. What I want to accomplish is to replace some special characters, but I haven't written the code yet. So in the replace function we can at this moment just say that the function should print line for line the way I have tried to write. Can someone please correct this function? I can’t really get...

Any references on Dynamic Code Analysis?

Yesterday I was reading about debugging techniques and found Valgrind to be really interesting. It seems to use techniques from dynamic code analysis. And I followed a link from the original reference to something else called Path Profiling. I tried Googling but I guess I am using the wrong terms to search for a good reference on these ...

Bot following a grid in reverse order

I am supposed to write a program in C only. It's code for a grid follower. I have defined a co-ordinate system of the grid (0-5,0-5). Also the bot orientations (+y,-y,+x,-x) and positions are defined. (I would welcome tips on how to write good code for this.) Now as my bot moves through the grid and goes to some coordinate (x,y) in the...

C Programming - Malloc Structs and undefined arrays

I am writing a program in C and I am trying to create these structs. I have three of them: the first consisting of 2 ints and 2 chars, the second consisting of an int and an undefined array of pointers to the first one, and a third which contains 4 longs and 2 ints along with an undefined array of pointers to the second. I am having ...

c udp chat testing

I am writing a udp chat application in c. I need to test if messages are received in an incorrect order. CAn anyone please tell me of a tool I can use to delay certain messages? also please tell me how to use it? thank you very much in advance! also I am using ubuntu x86_64 and OSX 10.6.4. A tool in either OS will work ...

fread() isn't writing to the buffer.

#include <Windows.h> #include <stdio.h> int count = 0; FILE* pFile = 0; long Size = 0; void *memfrob(void * s, size_t n) { char *p = (char *) s; while (n-- > 0) *p++ ^= 42; return s; } int main() { fopen_s(&pFile, "***", "r+"); fseek(pFile, 0, SEEK_END); Size = ftell(pFile); char *...

C: Passing an array into a function 'on the fly'

I have a function, and I want to pass an array of char* to it, but I don't want to create a variable just for doing that, like this: char *bar[]={"aa","bb","cc"}; foobar=foo(bar); To get around that, I tried this: foobar=foo({"aa","bb","cc"}); But it doesn't work. I also tried this: foobar=foo("aa\0bb\0cc"); It compiles with a w...

libmemcached problem

Hi all, when i run the libmemcached example code on my ubuntu, it gave me the error "undefined reference to `memcached_create'", anyone can help ? thanks #include <libmemcached/memcached.h> int main(int argc, char **argv) { //memcached_servers_parse (char *server_strings); memcached_server_st *servers = NULL; memcached_st *mem...

Cross Platform C?

I am running Linux Ubuntu 10.04 and I have a Windows 7 machine and a MacBook running Mac OS X 10.6.4. How can I write a simple C program (as in NOT QT!) like: #include <stdio.h> int main(int argc, char **argv) { printf("Hello Linux and Mac and Windows!") return 0; } to run on all my machines without having to compile this pro...

Why does fwrite have both size and count parameters when just bytes to write would suffice?

Possible Duplicate: What is the rationale for fread/fwrite taking size and count as arguments? In C, fwrite and fread take both the number of elements to write and the size of each element. It seems like just having a parameter that tells the number of bytes that should be written would more obvious and more general because th...

How do I implement a bit array in C / Objective C

iOS / Objective-C: I have a large array of boolean values. This is an inefficient way to store these values – at least eight bits are used for each element when only one is needed. How can I optimise? ...

C Variable from Terminal

Hey guys, I'm writing a program to read a file and display the number of lines and words in said file, simple stuff. What I want is to be able to run the program from terminal (running Ubuntu) by simply typing: count But I'm not sure how to get the filename into a variable in the C program. Little help please? Thanks in advance. ...

Why is variable declaration so simple in scripting languages like php, perl but not in Java, C etc?

In php/perl we can simply say $a='hi" and then $a=1 without needing to declare its type. But there are type casting errors in java for the same. Why this difference? ...

the role of #ifdef and #ifndef

#define one 0 #ifdef one printf("one is defined "); #ifndef one printf("one is not defined "); In this what is the role of #ifdef and #ifndef, and what's the output? ...

Simple C scanf does not work?

If I try something such as: int anint; char achar; printf("\nEnter any integer:"); scanf("%d", &anint); printf("\nEnter any character:"); scanf("%c", &achar); printf("\nHello\n"); printf("\nThe integer entered is %d\n", anint); printf("\nThe char entered is %c\n", achar); It allows entering an integer, then skips the second scanf com...

Why can't we declare a static variable within a structure in the C programming language?

Why can't we declare a static variable within a structure in the C programming language? ...

Help locate C sample code to read lua command line arguments

I am looking for sample code in C which reads Lua command line arguments. Any help? ...

Set screen resolution in game programming

I have to make a multiplayer game and give the users(on different) an option to change their screen resolution in order to sustain their hardware requirements.Similar to counterstrike. How can I implement this in c ? how can I give the users sitting on different computers an option to change their screen resolution ? ...

Opencv Kalman filter

Hi, I have three gyroscope values, pitch, roll and yaw. I would like to add Kalman filter to get more accurate values. I found the opencv library, which implements a Kalman filter, but I can't understand it how is it really work. Could you give me any help which can help me? I didn't find any related topics on the internet. I tried to ...

Problems with byte-reversing an integer

Godday all. Could someone please explain the logical difference in these two implementations of a byte-reversing function. Example 1: uint32_t byte_reverse_32(uint32_t num) { static union bytes { uint8_t b[4]; uint32_t n; } bytes; bytes.n = num; uint32_t ret = 0; ret |= bytes.b[0] << 24; ret |=...