c

How do I check if a value matches a string

Major brainfreeze while learning C here. I have a struct here with something like: char *sname; ........ players[i].sname equalling "James". I need to check for equality between values like so: if (players[i].sname == 'Lee') but am not having much luck. Is there a str function I should be using or is there anyway to fix up my if...

Gtk per widget accelerators

I build a composite widget and would like it to have it's own accelerators (hotkeys) available only when it is in focus. The only Idea I have so far of how to accomplish this is to change out the accelerator group in the top level when ever my widget goes in and out of focus. It seems like there should be a better way. ...

Duplicate file descriptor with its own file offset

How can one create a new file descriptor from an existing file descriptor such that the new descriptor does not share the same internal file structure/entry in the file table? Specifically attributes such as file offset (and preferably permissions, sharing and modes) should not be shared between the new and old file descriptors. Under b...

gtk composite widget focus

I created a composite widget with webkit_webview widget stored in scrollwed window with a gtkvbox base widget. How do make to so the base gtkvbox widget is in focus whenever any of the contained widgets have focus? Specifically, I am trying to add accelerator that should only be active when the composite widget is in focus. To determine ...

Is there a standard function in C that would return the length of an array?

Is there a standard function in C that would return the length of an array? ...

MapViewOfFile with pointers between threads

I have some programs that use MapViewOfFile to share data, but I am getting strange access violations that seem to be from accessing the mapped file data. Some of the shared data has pointers, however these pointers are only set and used by one process, but by several threads within the process. I understand that you can't use pointer...

C read binary stdin

Hey guys, I'm trying to build an instruction pipeline simulator and I'm having a lot of trouble getting started. What I need to do is read binary from stdin, and then store it in memory somehow while I manipulate the data. I need to read in chunks of exactly 32 bits one after the other. How do I read in chunks of exactly 32 bits at a ti...

What are the differences between exp10 and exp in C?

Another basic question I just must ask. Any answer is much appreciated. ...

MySQL C API custom values

I have been working with the tutorial on MySQL C API from http://zetcode.com/tutorials/mysqlcapitutorial/ the following example is working fine: #include <my_global.h> #include <mysql.h> int main(int argc, char **argv) { MYSQL *conn; conn = mysql_init(NULL); mysql_real_connect(conn, "localhost", "zetcode", "passwd", "testdb", 0, NULL...

eye detection sensitiveness

// face implant.cpp : Defines the entry point for the console application. #include <stdio.h> #include "stdafx.h" #include <cv.h> #include <cxcore.h> #include <highgui.h> void drawImage(IplImage* target, IplImage* source, int x, int y);// function prototype int _tmain(int argc, _TCHAR* argv[]) { CvMemStorage* storage = cvCrea...

Visual C++ standards compliance

Hey, I was wondering if, and to what degree, does Microsoft's Visual C++ compiler conform to the current C (C90/C99) and C++ (ISO/IEC 14882:2003) standards. Unfortunately I'm only able to find partial information on the subject, I may be looking at all the wrong places. Any pointers to related resources are much appreciated. Thanks in ...

Fast Multiplication

Hi! I'm writing code for a microprocessor with fast integer arithmetic and not so fast float arithmetic. I need to divide an integer by a number from 1 to 9 and convert result back to integer. I made a float array with members like 0, 1, 0.5, 0.3333 etc. But i think there is MAGIC constants (like 0x55555556) for a numbers except (1/3)....

Unwanted sal.h warnings

I'm trying to use VS 2008 for compiling some C code. I configured the project to use ANSI C standard without any language extensions. I also upped the warning level from 3 to 4. Upon building the project I always get this warning: c:\program files\microsoft visual studio 9.0\vc\include\sal.h(108) : warning C4001: nonstandard extension ...

Putting strings into a 2D chararray in C.

How do I put strings into an 2D char array from (for example) a file? char buffert[10][30]; int i = 0; while(!feof(somefile)) { fscanf(somefile, "%s", temp); buffert[i][] = temp; i++; } This will not do it. ...

GTK List with images and Text and other widgets.

Hello every one, I am building a simple chat application under GTK+ and C, In that i need to display List of contacts like follows. 1. Window Containing contact list with contacts Presence and status Icons and name. +-----------------------------------------+ | [PresenceImage1] [Name1] [StatusImage1] | | [PresenceImage2] [Name2] [Stat...

identify the exact header file

I am using some macro in my source file (*.c ) . Is there any way during compilation or from the library that I can identify the exact header file from which this particular macro is getting resolved ? The issue is we are using a macro #defined to 10 in some header file, but the value being received in the code is 4 . So instead of g...

C struct initialization using labels. It works, but how? Documentation?

I found some struct initialization code yesterday that threw me for a loop. Here's an example: typedef struct { int first; int second; } TEST_STRUCT; void testFunc() { TEST_STRUCT test = { second: 2, first: 1 }; printf("test.first=%d test.second=%d\n", test.first, test.second); } Surprisingly (to me), here's the...

Marking standard functions as deprecated/unusable

I have a large codebase that uses a number of unsafe functions, such as gmtime and strtok. Rather than trying to search through the codebase and replace these wholesale, I would like to make the compiler emit a warning or error when it sees them (to highlight the problem to maintenance developers). Is this possible with GCC? I already...

Please explain this behavior with character arrays/strings in C

I get this when I was trying something (just for understanding). Please explain this behavior: First attempt: void main() { char src[] = "vinay"; int i; // char name[5] = "test"; char *name= "abcde"; printf("%s \n", name); if (*(name+5) == '\0') printf("6th char is null\n"); strcpy(name,src...

Includes in inline assembly

We are working on a toy operating system as a assignment for a class. I'm having some trouble with writing of the kernel panic function. It should save all registers, call some printf-like function, then print the saved registers and halt the cpu. Right now it's defined as a macro: #define panic(...) \ do{ \ asm volatile("S...