c

how to solve errors like ‘struct iphdr’ has no member named ‘daddr’

I ran a program ( the link is - http://www.security-freak.net/raw-sockets/sniffer_eth_ip_tcp.c ) in my fedora core 5. On compilation , i get the following errors : [root@localhost ~]# gcc sniffer_eth_ip_tcp.c In file included from sniffer_eth_ip_tcp.c:12: /usr/include/linux/ip.h:97: error: expected specifier-qualifier-list before ‘u...

variable-length arrays

Hi, I just wonder if there is some overhead of using variable-length arrays? Can the size of array could be passed via command line argument at run time? Why is it introduced, compared to automatic and dynamically allocating an array? Thanks! ...

type of an array

Hi, when I need to pass an array to a function, it seems all the following declarations of the function will work void f(int arr[]) void f(int arr[4]) // is this one correct? for this: int a[]={1,2,3,4}; f(a); But when I assign an array to another array, it fails int a[]={1,2,3,4}; int b[4] = a; // error: array must be initiali...

How can my threaded image generating app get it's data to the gui?

A slow multiple precision implementation of a mandelbrot generator. Threaded, using POSIX threads. Gtk GUI. I've got a bit lost. This is my first attempt at writing a threaded program. I'm not actually trying to convert the single-threaded version of it yet, just trying to implement the basic framework. A brief description of how it wo...

Pipe is not receiving all output from child process

I wanted to open up a pipe to a program and read output from it. My initial inclination was to use popen(), but the program takes a number of options, and rather that fighting with shell quoting/escaping, I decided to use a combination of pipe(), fork(), dup() to tie the ends of the pipe to stdin/stdout in the parent/child, and execv() t...

Asterisk usage in Objective-C

I had a question regarding the use of asterisks in Objective-C. Just to be clear: I understand what pointers are and everything in procedural C. I was wondering two things though: 1) Why are all (references to) Objective-C objects pointers? Why not plain variables? (i.e. NSArray array = [[NSArray alloc] init];) 2) Why do you omit the a...

Literal string initializer for a character array

Hi, In the following rules for the case when array decays to pointer: An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T. (The exceptions are when the array is the operand of a sizeo...

Word and Double Word integers in C

I am trying to implement a simple, moderately efficient bignum library in C. I would like to store digits using the full register size of the system it's compiled on (presumably 32 or 64-bit ints). My understanding is that I can accomplish this using intptr_t. Is this correct? Is there a more semantically appropriate type, i.e. something...

Segmentation fault while using ferror() in a simple program. Why?

Why is the following code giving segmentation fault? #include <stdio.h> #include <stdlib.h> int main() { FILE *file; file = fopen("text","r"); if (file == NULL) printf("Error READING FILE"); if (ferror(file)) printf("error reading file"); //line 9 return 0; } Doing backtrace in gdb gives:- > #0 0x00007ffff7...

Why is this program not showing the first line again and again?

#include <stdio.h> #include <stdlib.h> #include <string.h> char *readLine(FILE *inFile) //Simply reads line in a text file till "\n" { char *line = realloc(NULL, 1); char c; int i=0; while (!feof(inFile)) { c = fgetc(inFile); if (ferror(inFile)) printf("Error reading"); if (c == 10) ...

semop() returns error EINVAL

Hi, all I'm writing a program with two processes operate on a semaphore in the ping-pong mode. The program first calls semget() to acquire a semaphore of size 2, semaphore #0 is initialized with value 1 while semaphore #1 is initialized with value 0. The code is as following: #include <sys/types.h> #include <unistd.h> #include <stdlib....

C: Structs and array - overview and help needed

Hi, in my phase of (re)learning C, I'm often facing problems with arrays and structures (and pointers). This is a little test I wrote. #include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct { char name[10]; } man; int main (int argc, const char * argv[]) { int i; man john; strcpy(john.name, "john"); ...

How do I create multiple but independent modal dialogs in GTK+?

I have the following code that uses GTK+ widget toolkit to display a window with a button. Clicking this button will show a modal dialog. Note that the call to gtk_dialog_run will recursively start another instance of the main loop, i.e. the on_click function will not return until the dialog box is dismissed. I would like to have two of...

globals, re-entrant code and thread safety

I'm trying to decide whether to implement certain operations as macros or as functions. Say, just as an example, I have the following code in a header file: extern int x_GLOB; extern int y_GLOB; #define min(x,y) ((x_GLOB = (x)) < (y_GLOB = (y))? x_GLOB : y_GLOB) the intent is to have each single argument computed only once (min(x++,...

Concatenating/Merging/Joining two AVL trees

Assume that I have two AVL trees and that each element from the first tree is smaller then any element from the second tree. What is the most efficient way to concatenate them into one single AVL tree? I've searched everywhere but haven't found anything useful. ...

print last -n lines of input

#include <stdio.h> #define MAXLINES 5000 /* Maximum number of lines to display. */ char *lineptr[MAXLINES]; /* Pointer to input lines. */ #define BUFFERSIZE 1000 #define DEFAULT_LAST 10 int readlines(char *lineptr[], char *buffer, int maxlines); static void unwrap(char *buffer, int index); static void reverse(char *lineptr[...

pointers to functions: cant compile

#include <stdio.h> #include <string.h> #define MAXLINES 5000 char *lineptr[MAXLINES]; int readlines(char *lineptr[], int nlines); void writelines(char *lineptr[], int nlines); void qsort(void *lineptr[], int left, int right, int (*comp)(void *, void *)); int numcmp(char *, char *); int main(int argc, char *argv[]) { int nlines; ...

Is %dn a format string ?

Hi , I recently came across this line in a code - fprintf(logfile," |-IP Version : %dn",(unsigned int)iph->version); Is "%dn" here a format string ? If so , what does it signify ? ...

How do disk pointers work?

Suppose I want to store a complicated data structure (a tree, say) to disk. The internal pointers which connect nodes in my data structures are pointers, but I can't just write these pointers to disk, because when I read the data structure back the memory locations will have changed. So what is the right way to store the pointers on di...

Write a program that will print "C" if compiled as an (ANSI) C program, and "C++" if compiled as a C++ program.

Taken from http://www.ocf.berkeley.edu/~wwu/riddles/cs.shtml It looks very compiler specific to me. Don't know where to look for? ...