c

c run time model

see code from programming pearls http://www.cs.bell-labs.com/cm/cs/pearls/timemod.c and also my effort to do myself #include <stdio.h> #include <time.h> #include <stdlib.h> #include <math.h> #define maxn 100000 int x[maxn]; int startn=5000; int n; //function to be timed int intcmp(int *i,int *j) { return *i-*j;} #define swapmac(i...

How can I make a library that writes to FILE * write the data to memory instead? (C programming)

I am facing a problem where the C library exposes only an interface that writes the data to a C FILE structure. This means all the data get saved to disk. I want this library to save the data to memory instead. Is there a way to emulate FILE structure in my code and make it save the data in memory instead? I imagine FILE has various poi...

What is the correct usage of realloc()?

Can anyone summarize what is the correct usage of realloc()? What do you do when realloc() fails? From what I have seen so far, it seems that if realloc() fails, you have to free() old pointer. Is that true? Here is an example: 1. char *ptr = malloc(sizeof(*ptr) * 50); 2. ... 3. char *new_ptr = realloc(ptr, sizeof(*new_pt...

Can FFmpeg encode video in VP8 codec?

Can FFmpeg encode video in VP8 codec? (I mean its trunk vercion) ...

Who determines the ordering of characters

I have a query based on the below program - char ch; ch = 'z'; while(ch >= 'a') { printf("char is %c and the value is %d\n", ch, ch); ch = ch-1; } Why is the printing of whole set of lowercase letters not guaranteed in the above program. If C doesn't make many guarantees about the ordering of characters in internal form, then...

Check a float variable for existence.

I have to check a float variable to determine the existence of a particular variable. Ideally it should have been a bool value or at least an int. Because of interface constraints and legacy code I am not able to change the data type to bool. So if I've to make a check, can I directly do it as shown below in the sample code: void c...

i like to learn linux c and c++!!! help need

hello pals, i like to build an application using linux c and c++. i know c and c++ and experienced it in turbo c++ v3. but i need to learn and know about gcc or g++ dev in linux. i have done a dbms application using c++ using turbo c for ms dos system. now, i need to develop it across linux with good gui's and functionalities like netwo...

Safe conversion from double to unsigned 64 bit integer

On my platform this prints 9223372036854775808. double x = 1e19; std::cout << static_cast<unsigned __int64>(x) << '\n'; I tried Boost.NumericConversion, but got the same result. Splitting x into 2 equal part, then adding together converted halves give the correct result. But I need a generic solution to use in a template code. Thank...

Virtual Instance of a C compiler on client browser

Is there a way I can create a virtual instance of gcc compiler on the client browser when the client opens my website?? By doing so, I can directly pass the user .c file as argument to my compiler instance and then execute it without having to make a POST call to server and execute the file there??? ...

How is printf statement interpreted?

How is the following line interpreted by gcc Compiler: printf("HELLO"); I want to know this because when I am running following program: main() { printf(5+"Good Morning"); } The program is printing Morning I understand that the compiler is starting the printing from the 5th index. But Why? ...

EXC_BAD_ACCESS While calling malloc function

hi I have the following function but sometimes it fails on the malloc function call and I don't know the reason,I thought that it may be due to lack of heap size but I have monitored the heap and I understood that I have enough space available for memory allocation when malloc fails ,can any one suggest anything to me char *substr(...

complex number types in mixing C(99) and C++

I'm writing a math library, the core of it is in C++. Later it may be implemented in pure C (C99 I suppose). I think I need a C like API so that I can get Python and matlab and the like to use the library. My impression is that doing this with C++ is painful. So is there a good or standard or proper way to cast between double complex *s...

Embeddable formula interpreter

I need something to embed in my C/C++ program to interpret formulas of the like x*log(x) or sin(x). I would like something small and simple, otherwise I can just embed Python, or Ch, or Scheme, or you name it. But all I need is simple formulas. I have searched the web without luck. Although I don't require it, performance (e.g., the use ...

determining largest value using function

user have to input 10 numbers and the program should read the largest number.the largest should be done in function..i can do the looping make user input 10 numbers but i don't know how to do the function to determine the largest..please help me!!! here is my code.. #include <stdio.h> int main () { int largest; double total=0; int x;...

Problem porting sudoku solver from C to Python

I recently wrote a sudoku solver in C to practice programming. After completing it I decided to write an equivalent program in Python for a comparison between the languages and more practice and this is where the problem is. It seems to be that a global variable (sudokupossibilities[][][]) I declared outside the while loop isn't availabl...

Mapping DMA buffers to userspace

hi everybody, i am writing a device driver on linux-2.6.26. I want to have a dma buffer mapped into userspace for sending data from driver to userspace application. Please suggest some good tutorial on it. Thanks ...

How to declare triple pointers in array of pointers...

How to declare a triple pointer with array of pointers like i have char *mainmenu[] = {"menu1", "menu2", "menu3"} see the picture How to connect my menu1,2,3 with those from the picture m1p1 m2p1 ??? I just need the syntax please help me ... ...

Funtion sizeof() in C

Consider the program main() { printf("%d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); } output from a gcc compiler is: 4 2 4 Why is it so? ...

Program misbehaves 25% of the time

Inspired by this topic, I decided to write a simple program that does exactly that. The logic isn't complicated and I have a working program 75% of the time.. The amount of asked numbers is defined as #define BUFSIZE x, where x can be an arbitrary int. The problem arises when ((BUFSIZE+1) % sizeof(int)) == 0. So for example, if BUFSIZE=...

bluetooth notification when turned on/off.

Hi All, Is there any way i can get a notification when bluetooth is turned on/off. This is for a personal project not targeted for AppStore. Are there any C/Mac API's for the same? ...