c

How does scanf() really work?

On Windows, char c; int i; scanf("%d", &i); scanf("%c", &c); The computer skips to retrieve character from console because '\n' is remaining on buffer. However, I found out that the code below works well. char str[10]; int i; scanf("%d", &i); scanf("%s", str); Just like the case above, '\n' is remaining on buffer but why scanf s...

Accessing a structure variable double pointer

Some code: typedef struct _WDF_USB_DEVICE_SELECT_CONFIG_PARAMS { ULONG Size; WdfUsbTargetDeviceSelectConfigType Type; union { struct { PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; PUSB_INTERFACE_DESCRIPTOR* InterfaceDescriptors; ULONG NumInterfaceDescriptors; } Descriptor; struct { PUR...

Problems with popen/pclose in Solaris

Hi guys I hope anyone can help me. I'm running a simple program in C, running in Solaris 8, and I found a problem while using popen/pclose. FILE * stream; stream = popen("ps -ef | grep "pattern"); if(pclose(stream)){ printf("Erro no fechamento da stream\n"); } The pattern in grep command it's just a filter that I use to treat...

need programs that illustrate use of settimer and alarm functions in GNU C

Can anyone illustrate the use of settimer or alarm function in gnu C , with some program examples ,please ? I have a program that continuously processes some data , and i need to set a timer / alarm that goes off every t seconds , in response to which , i need to store the processed data into a file. This file writing has to be asynchro...

Obtaining compiler include (and linker library) search paths for C code with JNI portably

I have a shared C library, libfoo.so, for which I'm creating a JNI interface. In order to compile the JNI interface library, libfoojni.so, compiler include search paths must be specified. For example, on Linux (using GCC) the following compiler flags are required: -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux. Unfortunately, the l...

Checkpointing and restarting X11 applications

My task is to checkpoint and restart X11 applications. Therefore I use the BLCR (Berkeley Lab Checkpoint/Restart (BLCR)) tool. Due to the fact that BLCR is not able (without modifications) to reinitiate the connection to the X-Server, I used an interposition library to log all Xlib function calls with their parameters to a text file. ...

XML Library for C/C++

Hey I'm looking for an XML parser for C/C++, just a parser which I give a string as an argument and it returns me a parsed document represented by a class/struct. The problem is that I am compiling it for the ARM9 processor and I need really just simple code no ./configure and stuff like that and no specific Makefile, just some files wh...

What is the difference between these two forms of inline assembler in C?

Background: I've been tasked with writing a data collection program for a Unitech HT630, which runs a proprietary DOS operating system that can run executables compiled for 16-bit MS DOS, albeit with some restrictions. I'm using the Digital Mars C/C++ compiler, which seems to be working very well. For some things I can use standard C l...

Best encryption library for mobile devices ?

Hello I have been using LibTomCrypt to use SHA1 encryption ( for data integrity checking ) on mobile devices (iPhone OS and Android for the moment ). I was wondering if anyone is using anything else, things to consider are Portability ( C preferred but C++ is also an option ), and libraries size ( small == better for my particular needs ...

Effect of using a comma instead of a semi-colon in C and C++

I've noticed on a number of occasions when refactoring various pieces of C and C++ code that a comma is used rather than a semi-colon to seperate statements. Something like this; int a = 0, b = 0; a = 5, b = 5; Where I would have expected int a = 0, b = 0; a = 5; b = 5; I know that C and C++ allow use of commas to seperate statem...

Some question about Cygwin[linux in windows] (socket,thread,other programming and shell issues)

I have some question about cygwin : Can I use Cygwin develop socket based code? Does Cygwin have read() and write() functions that work with file descriptors? Can I use Pthread library in Cygwin? Does code that compiles in Cygwin also compile in Linux without any change or with little change? Will an executable file that built by Cyg...

What is the downside of using the preprocessor to define a function call

I would like to know what the cons are of using the preprocessor in such a way: #define SOME_FUNCTION someFunction(someArgument) Basically I feel like this is wrong (or certainly not a best practice) - but I'm not sure why... my preprocessor skills are rusty at best. thanks, A ...

Converting std::list to C friendly type

What's the most elegant way to return a std::list object from a shared lib function (implemented by C++ code) to a C consumer? I know for std::vector, we can return the address of the 1st element of the vector and have the consumer treat it as an array, but std::list is implemented as a linked lis. ...

Simple Interaction with an Active MATLAB Session from Outside MATLAB

I'm trying to give a Java application the ability to change the working directory within an active session of MATLAB. Basically, the user will press a button to launch MATLAB. Then, they will be able to press other buttons that change the working directory of the active MATLAB. I've tried a few different approaches, but with no luck. I'v...

What is wrong with this C cast

I came across this in an IRC channel yesterday and didn't understand why it was bad behavior. #include <stdio.h> int main(void) { char x[sizeof(int)] = { '\0' }; int *y = (int *) x; printf("%d\n", *y); } Is there any loss of data or anything? can anyone give me any docs to explain further about what it does wrong? thanks! ...

array_length in C

I wrote an array_length function like this: int array_length(int a[]){ return sizeof(a)/sizeof(int); } However it is returning 2 when I did unsigned int len = array_length(arr); printf ("%i" , len); where I have int arr[] = {3,4,5,6,1,7,2}; int * parr = arr; But when I just do int k = sizeof(arr)/sizeof(int); printf("%i", ...

Premptively getting files into Windows page cache

I have a program written in C that allows the user to scroll through a display of about a zillion small files. Each file needs to undergo a certain amount of processing (read only) before it's displayed to the user. I've implemented a buffer that preprocesses the files in a certain radius around the user's position, so if they're worki...

Incrementing variables using pointers

I'm very new to dealing with pointers, and my C knowledge is fairly small. I'm trying to understand pointers. I wrote the following code to print a list of variables (a to f) like so: 0 1 2 3 4 5 I wrote the following code to do this: #include <stdio.h> int main(){ int a,b,c,d,e,f; int *p; int i; a = b = c = d = f = 0; p = ...

What are the differences between const and volatile pointer in C?

What are the differences between const and volatile pointer in C? ...

I have a binary search tree and I want to copy the nodes to an array with inorder (recursive function).

Hi I have a BST binary search tree typedef struct Treenode *SearchTree; struct Treenode { int Element; SearchTree Left; SearchTree Right; }; and I want to create a function FillArray(int sizeoftree, tree, int array[]) And I want to use an array and copy the nodes of the tree in the array. How can I do this? the foll...