c

Implement an array of stacks in C

Implement an array of stacks where stacks are defined : typedef struct StackNode { int data; StackNode* next; } StackNode; Each array element points to a stack, each stack is initialized as an empty stack. When you start adding elements it will start adding them to the stack in Stacks[0]; if you say -2 in stdin and then 4 for...

scanf not to exceed buffer overrun

Hello, C99 gcc I have a buffer and I don't want the user to enter anymore to avoid a buffer overrun. I am using scanf and have done like this: char buffer[30] = {'\0'}; scanf("%30s", buffer); However, I know I am protected if the user enters more than 30. However, if the user enters more than 30. Will the buffer be null terminated?...

Access function pointer defined in a structure?

Write a program to access the function "foo" using the structure structure2. typedef struct { int *a; char (*fptr)(char*); }structure1; typedef struct { int x; structure1 *ptr; }structure2; char foo(char * c) { --- --- --- } ...

Reason and solution for error -"/usr/bin/ld: cannot find -levent "?

While compiling my program which is using libevent library I am using gcc option -levent. But I am getting this error - /usr/bin/ld: cannot find -levent I do not have libevent on my system so I am statically linking to it while compiling using gcc -o Hello -static -I libevent-1.4.12-stable/ hello.c -levent How can i resolve this? ...

How can I measure the execution time of a for loop?

I want to measure the execution time of for loops on various platforms like php, c, python, Java, javascript... How can i measure it? I know these platforms so i am talking about these: for (i = 0; i < 1000000; i++) { } I don't want to measure anything within the loop. Little bit modification: @all Some of the friends of mine a...

Continue to debug after failed assertion on Linux? [C/C++]

When an assertion fails with Visual C++ on Windows, the debugger stops, displays the message, and then lets you continue (or, if no debugging session is running, offers to launch visual studio for you). On Linux, it seems that the default behavior of assert() is to display the error and quit the program. Since all my asserts go through ...

Passing parameters dynamically to variadic functions

Hi there. I was wondering if there was any way to pass parameters dynamically to variadic functions. i.e. If I have a function int some_function (int a, int b, ...){/*blah*/} and I am accepting a bunch of values from the user, I want some way of passing those values into the function: some_function (a,b, val1,val2,...,valn) I don...

Why String is not a String when it is passed to C from Scheme?

From the Plt-Scheme installation I have an example of C/Scheme interaction. There are two files: curses.c and curses-demo.ss. These files are available here. I've compiled curses.c, and trying to run curses-demo.ss And I am getting the following error: "put: expects argument of type 'character, string, or byte string'; given "Hello Worl...

DO's and Donts while using pointers

Its a simple but important question. What are the do's and donts while using a pointers in C and C++ so as to make sure SEGMENTATION FAULT is avoided on AIX? Where char * are preferred over character array? ...

Generate a square waveform in C?

How to generate an efficient square waveform with varying duty cycle using C language? ...

What are the most common naming conventions in C?

Hi, What are the naming conventions commonly use in C? I know there are at least two: GNU / linux / K&R with lower_case_functions ? name ? with UpperCaseFoo functions I am talking about C only here. Most of our projects are small embedded systems in which we use C. Here is the one I am planning on using for my next project: C Na...

How to put records from a random access file into an array in the C programming language?

How do I put the records from the random access file DATA.data into the array allRecs[10]? /*Reading a random access file and put records into an array*/ #include <stdio.h> /* somestruct structure definition */ struct somestruct{ char namn[20]; int artNr; }; /*end structure somestructure*/ int main (void) { int i = 0; ...

What creates the stack?

Suppose in a program we have implemented a stack. But who creates the stack ? Is it the processor, or operating system, or compiler? ...

xerces-c 2.8 : error while loading shared libraries

Hi, I'm trying to compile a program running on an HP UX server on a Red Hat Linux. It uses xerces-c library to parse xml files. Compilation is ok, but when i try to run it, I get the following message ./a.out: error while loading shared libraries: libxerces-c.so.28: cannot open shared object file: No such file or directory ...

Can i execute any c made prog without any os platform???

i googled about it and some where i read .... Yes, you can. That is happening in the case of embedded systems As per i think, NO, its not possible. Any platform must have an operating system. Or else, your program must itself be an OS. Either soft or hard-wired. Without an operating system your component wouldn't work. Am i right or c...

how to link c++ program with HTML page???

i am working on php...!! Is it possible to link HTML page to c++/c at back end. means instead of php script i want to run c/c++ if Yes How?? ...

How to list all subdirectories in a given directory in C?

Is there a way to list all subdirectories in a given directory path in C? I was hoping I would be able to do it with the stat() function but it only works on files. ...

IOServiceAddMatchingNotification issue

Hello, void functions::start() { io_iterator_t enumerator; ...some code... result = IOServiceAddMatchingNotification( mNotifyPort, kIOMatchedNotification, IOServiceMatching( "IOFireWireLocalNode" ), serv...

Weird C program

Check the following code snippet struct st { struct st { int a ; int b ; } st; int a1 ; } ; struct st obj ; struct st obj1 ; int main() { return obj.a1 + obj1.b ; } Microsoft's compiler Visual Studio 6.0 compiles the program succesfully. I am confused with the use of 'struct st'. What is the size of ob...

x86 Assembly: What's the main prologue and epilogue?

Hello, I'm following this tutorial on x86 assembly. Every example so far uses what the author calls a "c-driver" program, compiled with the assembly module, for means of some "initialization". Something like: int main(void) { int ret = asm_main(); return ret; } And then the asm_main function is written normally, using a C calling...