c

Never defined structure

Is there any benefit in having never-defined structures in C ? Example in SQLite source code : /* struct sqlite3_stmt is never defined */ typedef struct sqlite3_stmt sqlite3_stmt; And the object is manipulated like so : typedef struct Vdbe Vdbe; struct Vdbe { /* lots of members */ }; int sqlite3_step(sqlite3_stmt *pStmt) { ...

Oddity with structs defined in files other than main.cpp

Hi everyone, I have found that a struct (with an array of doubles and one integer) defined in a separate Cpp-file, but called from main sends unreasonable values to cout for the array. Below what I hope to be a minimum example, along with the console output. My apologies should my code be scrambled -- I have been struggling a bit with ...

Help understanding the C stdarg macros (va_start ...)

Hi all, recently i came across this function (used in a logger class). I understand what it does, but i do not know how: void Reporter::print( const char* szFormat, ...) { // note: m_out is a FILE* va_list args; va_start(args, szFormat); vfprintf( m_out, szFormat, args); va_end(args); } I read the reference, but s...

system and CreateProcess()

I have a command,I need to execute the same using C Program. I have stored the entire command ,with arguments, in the variable cmdline. When I am using system(cmdline),it is working fine. But on using the following: ret = CreateProcess(NULL, cmdline, (LPSECURITY_ATTRIBUTES)NULL, ...

update statement in sqlite

sqlite3_stmt *updateStmt = nil; if (updateStmt == nil) { const char *sql = " update PPM set amount = ? "; if (sqlite3_prepare_v2(appDelegate.PPMdatabase, sql, -1,&updateStmt, NULL)!= SQLITE_OK) { NSAssert (0,@"Error while creating update statement. '%s'",sqlite3_errmsg(appDelegate.PPMdatabase)...

fast auto-guessing of date strings

For a huge number of huge csv files (100M lines+) from different sources I need a fast snippet or library to auto-guess the date format and convert it to broken-down time or unix time-stamp. Once successfully guessed the snippet must be able to check subsequent occurrences of the date field for validity because it is likely that the dat...

How to allow certain threads to have priority in locking a mutex use PTHREADS

Hi, Assume that the following code is being executed by 10 threads. pthread_mutex_lock(&lock) Some trivial code pthread_mutex_unlock(&lock) For purpose of explanations lets say the threads are T1, T2, T3.....T10. My requirement is that as long as T1 or T2 or T3( i.e any of T1, T2 or T3) is waiting for acquiring a lock, the other thre...

Correct syntax for C pointer datatypes

I vaguely recall seeing this before in an answer to another question, but searching has failed to yield the answer. I can't recall what is the proper way to declare variables that are pointers. Is it: Type* instance; Or: Type *instance; Although I know both will compile in most cases, I believe there are some examples where it is ...

What is the safest way to allocate and deallocate memory in C?

Using C, is there a safer way to allocate memory than using malloc? For example, is there a C equivalent of a smart pointer, or some handy function that someone has come up with that makes the process of allocation a little cleaner? I mean, sure, it's only one line anyway, but there must be a more concise way to get it done. I suppose...

Source IP from UDP packet in c under window OS

I want to get the source IP of UDP packet kindly guide me so that I can make it possible. I am working in c under windows platform. ...

How to replace strings in C, just using stdio.h??? Help, please!!!

i need to create a small program: user enter 1st string ex: I'm a beautiful girl then he needs to replace for example 'beautiful' to 'clever' can use just stdio.h and pointers as well help me, pls!!! ...

gtk+ printing list of image

Hello, In my gtk+ application i have list of images and i need to print it. I have code for printing one image: static void draw_page (GtkPrintOperation * oper, GtkPrintContext * context, gint nr, gpointer user_data) { MainWin* mw = (MainWin*)user_data; GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(...

What should the destination mac address be set to when sending packet outside of your local network?

If I use arp and arping on machines in my local network I get the mac addresses from them. In the same way I can construct and send a ARP request and collect the response to these machines. This is used since I build raw packets completely from scratchy (to allow spoofing of every possible field, including mac addresses if needed). But, ...

Segmentation fault in libcurl, multithreaded

So I've got a bunch of worker threads doing simple curl class, each worker thread has his own curl easy handle. They are doing only HEAD lookups on random web sites. Also locking functions are present to enable multi threaded SSL as documented here. Everything is working except on 2 web pages ilsole24ore.com ( seen in example down ), and...

Mixing post- and pre- increment/decrement operators on the same variable

Possible Duplicate: Why is ++i considered an l-value, but i++ is not? In C++ (and also in C), if I write: ++x-- ++(x--) i get the error: lvalue required as increment operand However (++x)-- compiles. I am confused. ...

How to replace strings in C, just using stdio.h???

It's a part of my final project; I don't understand C well. I have just this, and I don't know anything more. Please don't delete my question. I was looking for the answer a long time. I guess I'm not the only student with this problem. And why is there no option to send a private message or see a user's e-mail? wow, guys...actually i ...

graphics in c -rectangle

While working with graphics in C if I need to draw a rectangle ,How do I get its dimensions? ...

CUDA Basic Matrix Addition - Large Matrices

Hi all, I'm trying to add two 4800x9600 matrices, but am running into difficulties... It's a simple C=A+B operation... Here is the kernel: __global__ void matAdd_kernel(float* result,float* A,float* B,int size) { int x=blockIdx.x*blockDim.x+threadIdx.x; int y=blockIdx.y*blockDim.y+threadIdx.y; int idx=x*y+x; ...

What is the equivalent type in C for REAL(KIND=real_normal) in Fortran?

I have a problem with passing of an array from Fortran to a c function: In the fortran the array is defined as REAL(KIND=real_normal) , DIMENSION(:), ALLOCATABLE :: array call cFunc(array) If define the cFunc as void cFunc(double *data){...} Than the data contains only "garbage" values. Where is the problem in this case? (with in...

User defined array sizes in C

I'm reading through "Illustrated C" and the first exercise question asks: Program MATMUL multiplies matrices of fixed size. Make the program deal with any specified sizes. So below is the code that I have come up with thus far. However I read that all attributes need to be declared before the main function. So how do I get custom s...