c

What Linux IPC to use between a c program and a C++ Qt app?

Hi I have a old school c program that now and then need to tell a C++ Qt based application about some "events" that has occurred on my system. But when I started to work with this problem I noticed that some ipc techniques is quite easy to use in the c program. And then we have some Qt specific styles that works quite well in the "Qt...

c - dynamic memory

Hi everyone out there very first thanks to all of you for providing help. Now i want to know about double pointer. I'm doing code like this: int main() { int **a; a = (int*)malloc(sizeof(*int)*5); for (i=0;i<5;i++) { a[i] = malloc(sizeof(int)*3); } } Now i dont know if I'm doing it right. How can I put val...

c -language dynamic memory

hi thanx every body for their support but no one provide me the required information now i try to did that program like this #include<stdio.h> #include <stdlib.h> int main() { int **a,i,j; system("clear"); a=(int*)malloc(sizeof(int)*5); for (i=0; i<5; i++) { a[i]= malloc(sizeof(int)*3); for (j=0; j...

concurrent threads in C programming

I have encountered a problem while implementing wait and signal conditions on multiple threads. A thread needs to lock a mutex and wait on a condition variable until some other thread signals it. In the meanwhile, another thread locks the same mutex and waits on the same condition variable. Now, the thread which is running concurrently ...

Best way to do RAW socket programming involving Java.

I have some existing C code that uses ICMP raw sockets to do Ping and I need to use this code in Java as Java does not support ICMP packages. When I wrap the code in JNI and call it, the C code fails to obtain the socket when doing: socket(AF_INET, SOCK_RAW, 1); I guess that Java has dropped some privileges that disables the use of raw...

How is Assembly used in the modern day (with C/C++ for example)?

I understand how a computer works on the basic principles, such as, a program can be written in a "high" level language like C#, C and then it's broken down in to object code and then binary for the processor to understand. However, I really want to learn about assembly, and how it's used in modern day applications. I know processors ha...

Looking for library which implements LZW compression/decompression.

I need to learn how to do Lempel–Ziv–Welch compression using pen and paper for my algorithms and data structures class. Unfortunately we have only a couple of examples in our book of how it is done. I'd like to practice compressing and decompressing text using it, but I need to find a way to check if I'm right doing it right or wrong. On...

fprintf keeps putting in extra characters I don't want. Can't I stop this?

Im trying to write out an image file that has the following structure: P5 //magic number 512 512 //dimension of image 255 //max value per pixel [Image Data.....] The standard says after max value there should be a whitespace or newline, then the image data. For whatever mysterious reason, the code below >always< adds in 2 c...

find the output of the given code and explain it happens

#include<stdio.h> #include<conio.h> void main() { if(0xA) if(052) if('\xeb') if('\012') printf("tom hanks"); else; else; else; else; } ...

Structs on the stack (ANSI C)

Dear all Having started to study Ulrich Dreppers "What every programmer should know about memory" [1] series I got stuck when trying to reproduce the examples presented in section 3.3.2 Measurements of Cache Effects As far as I understand the structures should be allocated on the stack since then they are in memory one after another....

Differences between a shared object and an ordinary library in Linux

What are the main differences between binding to a shared object or to an ordinary object? Also how is this possible to share some variables between some programs and knowing that our variables are never changed by another program? ...

Ambiguous declarations

What is the difference between the following two declarations: 1. int foo(int); 2. int foo(int()); I am not sure if both the declarations are equivalent. What makes (2) different from (1)? ...

How bad is it to abandon THE rule in C (aka: return 0 on success)?

Hi all, in a current project I dared to do away with the old 0 rule, i.e. returning 0 on success of a function. How is this seen in the community? The logic that I am imposing on the code (and therefore on the co-workers and all subsequent maintenance programmers) is: .>0: for any kind of success/fulfillment, that is, a positive outcom...

Help building a Dll for C in Delphi

Hi, ive previously asked another questions about building my dll, but it seams like its heading in the wrong direction :) So I have reformulated and explained more her. So what im trying to build is a dll that will work as an interface between my delphi program and some one else's C program. What this dll must do is recive a String fr...

Linked Lists in C without malloc

#include <stdio.h> typedef struct node { int i; struct node *next; }node; node getnode(int a) { struct node n; n.i=a; n.next=NULL; return n; } main() { int i; node newtemp,root,temp; scanf("%d",&i); root=getnode(i); temp=root; while(i--) { newtemp=getnod...

How to get records from MySQL in c/c++?

This is pretty easy in PHP: $con = mysql_connect("localhost:".$LOCAL_DB_PORT, $LOCAL_DB_USER, $LOCAL_DB_PASS); mysql_select_db("db", $con); mysql_query("set names utf8", $con); $result = mysql_query("select ..."); while($row = mysql_fetch_assoc($result)) { ... } But what's the easiest way to do it with c/c++ in windows? ...

parse number from the string

Say I have the line in this format "word word 12 YR" or "word word 10 MO" and I want to convert it to char * containing either "12Y" or "10M" respectively. The format is two words followed by numerical followed by the word denoting the year or the month. words are space/tab separated. Currently, I am playing around with the s...

Random C/Objective-C questions

I have come across a few lines of coding I do not understand, and would be grateful for clarification: if(!(counter&7)) ds->direction = ts->direction; Thank you ...

Using hardware timer in C

Hi guys, Okay, so I've got some C code to perform a mathematical operation which could, pretty much, take any length of time (depending on the operands supplied to it, of course). I was wondering if there is a way to register some kind of method which will be called every n seconds which can analyse the state of the operation, i.e. what...

Vim auto-indentation: Align an array initialization which extends over multiple lines

Sometimes an array initialization in C extends over several lines, especially if the array is multidimensional. In Emacs the result of auto-indentation looks like this: int a[N][N] = {{0, 0, 6, 7, 0, 4, 0, 2, 0}, {0, 5, 0, 6, 0, 0, 0, 0, 1}, {2, 0, 0, 0, 0, 8, 0, 0, 4}, {4, 0, 9, 5, 0, 7, 0, ...