c

fflush and 'no disk space left'

I'm writing a program, some kind of database. While I was reading manual of fclose(3) I found that it calls fflush(3) to flush FILE* buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call fsync(2)). Because I'm writing a DB it is obvious that I want to prevent data loss. If there is no disk space an...

Accessing a label from outside a function

The code: /* ctsw.c : context switcher */ #include <kernel.h> static void *kstack; extern int set_evec(int, long); /* contextswitch - saves kernel context, switches to proc */ enum proc_req contextswitch(struct proc_ctrl_blk *proc) { enum proc_req call; kprintf("switching to %d\n", getpid(proc)); asm volatile("pushf\n" ...

Server Architecture for Embedded Device

I am working on a server application for an embedded ARM platform. The ARM board is connected to various digital IOs, ADCs, etc that the system will consistently poll. It is currently running a Linux kernel with the hardware interfaces developed as drivers. The idea is to have a client application which can connect to the embedded device...

What is p-notation in C programming?

I'm learning C right now and there is a conversion specifier %a which writes a number in p-notation as opposed to %e which writes something in e-notation (exponential notation). What is p-notation? ...

C programming, how can I get execution time of a program in milliseconds?

Hello, Currently I'm getting execution wall time of my program in seconds by calliing: time_t startTime = time(NULL); //section of code time_t endTime = time(NULL); double duration = difftime(endTime,startTime); Is it possible to get the wall time in milliseconds? If so how? Thanks in advance! alex ...

iPhone app crash logs -- How can I use them to debug my app?

I'm not an expert in programming in general. I can find my way around Objective-C and Xcode and build working apps with no huge problems but when BUGs arise I'm often lost as to where to begin. My app works fine on the sim but more often-than-is-comfortable it crashes on the device. I looked at the crash log to see if there was any clu...

Starting a thread for each inner loop in OpenMP

I'm fairly new to OpenMP and I'm trying to start an individual thread to process each item in a 2D array. So essentially, this: for (i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { a[i][j] = b[i][j] + c[i][j]; What I'm doing is this: #pragma omp parallel for shared(a,b,c) private(i,j) reduction(+:diff)...

Where to get simple opensource adpcm C\C++ encoder lib?

Where to get simple opensource pcm to adpcm C\C++ encoder lib? ...

What is the difference between a static and const variable?

Can someone explain the difference between a static and const variable? ...

What is wrong with my algorithm?

Alright, I've cooked up some code to reverse hex characters around as part of a fun exercise I made up. Here is what I have at the moment: #include <stdio.h> int main() { char a,b,c; while (1) { c = getchar(); if (!feof(stdin)) { a = c % 16; b = (c - a) / 16; c...

how to slow down a process ?

Suppose I have a program that runs in a given amount of time (say, three seconds). I want to run this program so that it runs n-times slower (specified on command line). How would you achieve it with (or better, without) changes to the program ? please note that adding a sleep at the end is not a solution. The program has to run slower,...

Check for UNIX command line arguments, pipes and redirects from a C program.

Hi, I have some problem to figure out how I can maintain the pipe and redirect functionality of a shell once I find out that there are missing command line arguments. If I for example use a scanf call, that will work with a re-direct or a pipe from a shell, but in absence of this I get a prompt, which I don't want. I would like to ac...

What's the meaning of #line in C language?

What's the meaning of #line in C language? Where would it be used? ...

How to write a full string to a file?

Hi, I'm programming in Windows right now, but portable code would be welcomed too. What I'm using right now is fwrite(4), but this function needs a maximum number of elements to be written to the file. I can use strlen(1) here but I'd like to know if there is any better way to do this. ...

Extracting the value represented by a particular set of bits in a number

How to extract the value represented by a particular set of bits in a given number i.e. if bits 11,12 & 13 are 1,1,0 then the value should be 6. What is the most efficient way of doing the same? Also, it should be generic. I should be able to give start and end bit positions and should be able to extract the value represented by the bit...

Finding the intersecting node from two intersecting linked lists.

Suppose there are two singly linked lists both of which intersect at some point and become a single linked list. The head or start pointers of both the lists are known, but the intersecting node is not known. Also, the number of nodes in each of the list before they intersect are unknown and both list may have it different i.e. List1 ma...

Variable definition in header files

My very basic knowledge of C and compilation process has gone rusty lately. I was trying to figure out answer to the following question but I could not connect compilation, link and pre-processing phase basics. A quick search on the Google did not help much either. So, I decided to come to the ultimate source of knowledge :) I know: V...

Smallest sum of pairs

Given 2N-points in a 2D-plane, you have to group them into N pairs such that the overall sum of distances between the points of all of the pairs is the minimum possible value.The desired output is only the sum. In other words, if a1,a2,..an are the distances between points of first, second...and nth pair respectively, then (a1+a2+...an...

What should I return for errors in my functions in C?

Hi, Currently I'm returning -1 in my custom functions in C if something wrong happens and 0 for success. For instance, working with a linked list and some function needs a non-empty list to work properly. If the list passed as argument is empty, I return -1 (error) and 0 if it's not empty and the function worked without a problem. Shou...

Deep copy of graph structure

I have a graph structure in C and want to make a deep copy of it (including nodes and edges). The structure looks like this: struct li_list { struct li_node n; }; struct li_node { struct li_node *next, *prev; }; struct gr_graph { struct li_list nodes; int nodecount; }; struct gr_node { struct li_node node; st...