c

Lookup .txt files

Firstly i must say that my english is not very strong, so please forgive me. I have got a question about my project. how do you search for text files on a local drive, i.e files with the .txt extension using the C programming language. ...

void * assignment problem

I want to take some fields from packet struct using pointer arithmetic.But what is wrong with the code below ? In first condition i think if i go 4 byte(2 short field) from beginning of packet i get tLow .But it does not give expected value.Additionally second case i want to get data field by going 12 byte from beginning of packet .What ...

Suggestions for concise index handling in circular buffer

I've implemented a circular buffer, and I would like a concise means of updating the buffer pointer while properly handling the wrap-around. Assuming an array of size 10, my first response was something like: size_t ptr = 0; // do some work... p = ++p % 10; Static analysis, as well as gcc -Wall -Wextra, rightly slapped my wrist for...

Forward declare FILE *

How do I forward declare FILE * in C? I normally do this using struct MyType;, but naturally this doesn't appear to be possible. If behaviour differs between C standards or compilers and with C++, this is also of interest. Update0 Why I want to do this aside: What I'm asking is how to forward declare a non-struct/"typedef'd struct" ty...

How to interrupt a fread call?

I have the following situation: There is a thread that reads from a device with a fread call. This call is blocking as long as there is no data send from the device. When I stop this thread it remains hanging inside this thread. Now I found the following inside the man page of fread: ERRORS On all systems that conform to the...

How to access outer block variable in inner block when inner block have same variable declaration?

int main(int argc, char** argv) { int i=5; { int i=7; printf("%d\n", i); } return 0; } If I want to access outer i (int i=5) value in printf then how it can done? ...

GetPixel in GDI

Using GetPixel, Is that right that you retrieve the pixel information that HDC temporarily store after you draw on each WM_PAINT call? ...

Typedef of structs

I am using structs in my project in this way: typedef struct { int str1_val1; int str1_val2; } struct1; and typedef struct { int str2_val1; int str2_val2; struct1* str2_val3; } struct2; Is it possible that I hack this definition in a way, that I would use only types with my code, like struct2* a; a = (struct2*...

C: How does nested braces for array of struct initialization work?

struct mystruct s[10] = {{0}}; This appears to initialize an array of structs to 0. How does the nested braces syntax work? ...

Maintaining a Python Object when embedding in C

Due to refactoring/reworking on a controller I've had to embed a Python Interpreter inside a C application. I can now call python functions and pass/get Objects into Python fine. The python code is a controller for a robot (currently simulated), this now needs make use of some C code for comparisons I'm making. Previously the Python ...

printf() statement makes a difference to my return value? - C Programming

Hi there, I'm experimenting with one of the functions in the K&R C Programming Language book and using pointers to write the strindex function rather than array notation. I have a strange problem that if I include a printf() statement at either of the two points in my code below then the function returns the correct index (6 in this cas...

How could these case conversion functions be improved?

As a learning exercise, my three functions—ToggleCase, LowerCase and UpperCase—each expect a pointer to an ASCII char string, terminated by the null character; they work as expected. Are there more efficient or faster methods of accomplishing this task? Am I breaking any unspoken rules of good C coding? I've made use of macros because...

GCC Inline Assembly Multiplication

I'm trying to learn GCC inline assembly on Linux (x86), and my first experiment was to try and implement integer overflow detection for multiplication. It seems easy enough, but it is having side effects which I don't understand. So, here I want to multiply two unsigned 8-bit integers, and see if the result overflows. Basically I just...

How is negative zero used in this context?

struct in_addr ipv4; ipv4.s_addr = (uint32_t)(-0) ...

Can popen() make bidirectional pipes like pipe() + fork()?

I'm implementing piping on a simulated file system in C++ (with mostly C). It needs to run commands in the host shell but perform the piping itself on the simulated file system. I could achieve this with the pipe(), fork(), and system() system calls, but I'd prefer to use popen() (which handles creating a pipe, forking a process, and...

memory allocation for structures.

Can someone please explain me this peculiar output: #include <stdio.h> typedef struct node { int i; struct node *next; }node; main() { node *p,*q; printf(" %u ",sizeof(node)); // 16 p = (node *)malloc(sizeof ( node ) ) ; printf(" %p ",p); // 0x1cea010 q = (node *)malloc(size...

Implicit Type Conversion..

#include<stdio.h> int main(void) { signed int a=-1; unsigned int b=1; int c= a+b; printf("%d\n",c); return 0; } According to the rule of Implicit type conversion, if one operand is unsigned int,the other will be converted to unsigned int and the result will be unsigned int in a binary operation. so here as b is unsigned i...

Mixing variables and integer constants in the Boost Preprocessor

I am using BOOST_PP for to do precompile computations in the preprocessor. I am focusing on an application where code size is extremely important to me. (So please don't say the compiler should or usually does that, I need to control what is performed at compile time and what code is generated). However, I want to be able to use the same...

How do I make my application use the Windows theme?

I'm working with some windows API to create a little application. I already created the buttons, windows, alright. But the problem is the components I created don't look like the OS theme. They look very simple: See the button as example. How do I enable the Windows theme? It can be in C or Delphi. ...

Bit Level Manipulation & Arithmetic Functions (In C)

Hey everybody. I am learning bit wise operation and arithmetic operations in C but I am a bit confused about some of it. I am working through some of the review questions in my book but the book only has answers for the odd number questions so I would like to pose some questions for you guys so I can tell if I am on the right track. Than...