c

c struct grabbing data by offset

Lets say I have this struct: typedef struct nKey { int num; widget* widget; } NUMBER_KEY; and a function: void dialKey(widget* widget) { // Need to print 'num' of the struct that this widget resides in } How do I go about accomplishing this? I tried something like: printf("%d", * (int *) widget - sizeof(int)); // F...

Looking for a bitwise operator.

Hi. I have a list of objects of the same class. The order of the list is not important. What i want to do, is to (using bitwise operations) determine whether i should set some field with an incremental value or not. But the trick is that i want need this operation to return false (must not set field) only for the first element. for (Ob...

abstract function pointers

How would I create an array of ten function pointers? What I have is a for loop, and I want to set a function pointer to a different function on each iteration. so: //pseudocode for i (0..10) function = array_of_functions[i]; //... ...

How can I time my C program?

I looked through old threads but could not find the answer to my question: How can I time the body of my function inside a C program? ...

Calling a function which is declared under the current function.

Hi All, I'm a newcomer to C and I have a problem when trying to call a function which is declared under the current function Ex: void test (){ test1 ();} void test1(){ } I could just move test1 above test, but I have this as well : void test () {test1 ()} void test4 () {test ()} void test3 () {test4 ()} void test1 () {test3 ()} So...

Any hand-on exercise to understand how a program is loaded into memory and get executed

Hi, I am curious about the things happend before main() is called , such like load the executable into memory , dynamic load of shared library. Do you have any suggestions how to understand these things by a hand-on exercise? The tools amd things I know of ,and using now, includes: strace disassemble readelf /proc/pid/map NOTES: ...

interposers on Windows

Is it possible to substitute system functions, as is possible on Linux and Solaris using the LD_PRELOAD For example by setting the environment variable: LD_PRELOAD=/path/to/mymalloc.so I would have my replacement malloc functions instead of in the C runtime already installed in the system libraries. All other functions in the system d...

C (gcc on linux): How do i convert a hex string "0xfffffff" to an integer ?

C (gcc on linux): How do i convert a hex string "0xfffffff" to an integer ? ...

Accessing same resource across restarts in Windows

I will write some thing in a file/memory just before system shutdown or a service shutdown. In the next restart of system, Is it possible to access same file or same memory on the disk, before filesystem loads? Actual requirement is like this, we have a driver that sits between volume level drivers and filesystem driver...in that part of...

Data structure for repeatedly splitting a string into smaller parts

Hello, I'm trying to write a function that repeatedly matches regexp patterns against an input string. The function should take pattern 1 match it against the input string and split it into parts of matching and non-matching segments. Pattern 2 would subsequently be used on those non-matching segments, until all input patterns are used...

Multithreading - Synchronization on Unix

Hi, I am facing sync related issue in multi threading. I have an shared library which applications use to build there applications. From the library I have created a thread which listen to the request coming and process it its is real time thread.From the library i have invoked an API which is sync in nature which will wait for response ...

Sending floating point number from server to client.

I am using TCP/IP socket programming. I have a floating point value stored in a variable ret_val in my server code which I want to send to the client which is waiting to receive it. How can I do it? ...

What is the best way to do a search in a large file?

I'm looking to apply a KMP (or similar) search to a large file (> 4GB). I'm expecting this to give me problems though.I can't copy it all to memory because there isn't enough space there. My question is, what is the best way to go about doing this search? Should I simply create a FILE* and do the search directly in the file, should I c...

seteuid() not working. Reason?

Hi, I'm completely new to C and I use it very rarely. This time i need it for a university project. I have to write a small c app that tests some modifications we made on the Linux kernel (on the scheduler). Inside the script I'd like to switch to another user to see the distribution of CPU times among the different users. So I start m...

Adjust tokens on non-privileged accounts (C, Windows)

I'm using the following code (which is a sample from the MSDN slightly modified) to check whether i have debug privileges on a process. If I don't I try to set them. int SetDebugPriv() { HANDLE TokenHandle; LUID lpLuid; TOKEN_PRIVILEGES NewState; if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &TokenHandle))...

How do I change the background color of a conditional macro in eclipse?

How do I change the background color of a conditional macro in eclipse? I am using the C/C++ version of eclipse so I would assume it would be associated with a mysterious preprocessor background color setting. Thanks, Chenz ...

Detect Debug Privileges on a process (Windows, C)

in a previous question I asked how to overcome the fact that in certain users the debug privileges were not there. Now, since I can't set something that doesn't exist, how would I check if a user has debug privileges? I know I have to use LookupPrivilegeValue(), I just can't figure where to read on the returned value that would indicat...

Multiple-writer thread-safe queue in C

I am working on a multi-threaded C application using pthreads. I have one thread which writes to a a database (the database library is only safe to be used in a single thread), and several threads which are gathering data, processing it, and then need to send the results to the database thread for storage. I've seen in mentioned that it ...

what is the use of tokens.h when I am programming a lexer?

I am programming a lexer in C and I read somewhere about the header file tokens.h. Is it there? If so, what is its use? ...

Why is this code causing a segmentation fault?

#include<stdio.h> void main() { FILE *fp,*fp1; char c; fp=fopen("test.txt","r"); fp1=fopen("test1.txt","w"); c=getc(fp); while(c!=EOF) { if (c=="") { c=getc(fp); continue; } else fprintf(fp1,"%s",c); c=getc(fp); } fclose(fp); fclose(fp1); } ...