c

GNU Readline: how do clear the input line?

I use GNU Readline in the "select" fashion, by registering a callback function like so: rl_callback_handler_install("", on_readline_input); And then hooking up rl_callback_read_char as the callback for my select() loop for STDIN_FILENO. That's all pretty standard stuff, and works fine. Now, my program asynchronously prints messages ...

Setting up dependencies on Visual C++ 2008 Express

How do I set up Visual C++ 2008 Express to point to the required libraries and include directories of a 3rd party C library? ...

What are these GCC/G++ parameters?

Hello, everyone. I've been using the UVa Online Judge to solve some programming challenges, and, when submitting my solutions, I'm told the judge will compile my code using the following parameters to GCC/G++ that I don't know: -lm -lcrypt -pipe -DONLINE_JUDGE. What do they do? Thank you very much in advance! ...

C Working with char pointers

Hi guys, just brushing up on some C for a class and I've run across a little something that makes me scratch me head. For this code: char * findString(const char * s){ /* Allocate space */ char * ret = malloc(strlen(s) + 1); /* Copy characters */ char * n; n = ret; for ( ;*s != 0; s++) if (isLetter(*s)) *n++ = *s; *n = 0; ...

How to write program during compiling?

Write a small C program, which while compiling takes another program from input terminal, and on running gives the result for the second program. (NOTE: The key is, think UNIX). Suppose, the program is 1.c Then, while compiling $ cc -o 1 1.c int main() { printf("Hello World\n"); } ^D $ ./1 Hello World $ ...

C - Largest String From a Big One

So pray tell, how would I go about getting the largest contiguous string of letters out of a string of garbage in C? Here's an example: char *s = "(2034HEY!!11 th[]thisiswhatwewant44"; Would return... thisiswhatwewant I had this on a quiz the other day...and it drove me nuts (still is) trying to figure it out! UPDATE: My fault...

How do I optimize

What I'm trying to do is take this code: char naive_smooth_descr[] = "naive_smooth: Naive baseline implementation"; void naive_smooth(int dim, pixel *src, pixel *dst) { int i, j; for (i = 0; i < dim; i++) for (j = 0; j < dim; j++) dst[RIDX(i, j, dim)] = avg(dim, i, j, src); } and replace the function call avg(...

Sending IOCTL from IRQL=DISPATCH_LEVEL (KbFilter/KMDF)

I am using the KbFilter example in the WDK, trying to send an IOCTL in a function that is called by KbFilter_ServiceCallback and therefore is executed at DISPATCH_LEVEL. The function just has to send an IOCTL and return, am not waiting for an output buffer to be filled so it can be asynchronous, fire and forget. I am currently using the...

Problem regarding inline assembly and function overwriting.

Somebody over at SO posted a question asking how he could "hide" a function. This was my answer: #include <stdio.h> #include <stdlib.h> int encrypt(void) { char *text="Hello World"; asm("push text"); asm("call printf"); return 0; } int main(int argc, char *argv[]) { volatile unsigned char *i=encrypt; while(*i!=0x00) *i...

Is there a way to use fopen_s() with GCC or at least create a #define about it?

Hi, MSVC compiler says that fopen() is deprecated and recommends the use of fopen_s()... Is there any way to use fopen_s() and still be portable? Any ideas for a #define? Thanks. ...

How to get the last key pressed without stopping the C programm ?

Writing an application with command line interface and I would like to know at any time if F1 or esc or an arrow key is pressed. What is the simplest way of doing this. I would like to avoid using readline type library. Edited: Linux specific question. It is not multithreaded ...

Why is curses on linux giving me following error?

Trying to get getch() working to capture key press. #include <curses.h> ... ... WINDOW *w; char f; w = initscr(); timeout(3000); f = getch(); endwin(); is giving me following error:- undefined reference to `wgetch' undefined reference to `stdscr' ...

C: copying struct/array elements

Hello everyone, I have a file in a known format and I want to convert it to a new format, eg.: struct foo { char bar[256]; }; struct old_format { char name[128]; struct foo data[16]; }; struct new_format { int nr; char name[128]; struct foo data[16]; }; s...

Help understand C Stack

I am trying to understand low-level memory manager in C especially Stack. As I was told, when a function is called, a return address was push on a stack. Then local variables is located after that. So I write a small program to investigate this. Here is my program: #include <stdio.h> void TestStack(); void DoTestStack() { char x1...

How to call MATLAB code from C?

I have some code that plots triangles in MATLAB. I need to be able to somehow execute this code from my C program which generates these points. Is that possible? How can it be done? Just a thought: Can I somehow embed MATLAB code in C, so that it can compile on a C compiler? ...

How do I detect the presence/absence of internet connection on a machine?

I need to detect the presence/absence of internet connection. More precisely, let us suppose that the application is broken up into 2 parts - A and B. A is responsible for checking whether or not the system is connected to the internet. If it finds that there is no connection, it starts up part B. And as soon as it detects that there is...

Problem with kbhit()[and getch()] for Linux.

while(ch != 'q') { printf("looping\n"); sleep(1); if(kbhit()) { ch = readch(); printf("you hit %c\n",ch); } } This code gives me a blocking getch() like functionality. I am trying to use this code to capture up down arrow keys. Added: Trying to capture key codes of up arrow gives me 3 chars 27, 91 and 65. Using i...

Scripting language for C/C++??

Is there a scripting language for C++ (like perl) which can be used for rapid development and use some tool which can convert into C/C++ program to get higher performance for deployment? EDIT: Based on some commented, let me clarify the question. I should be able to convert script into C/C++ program or binary without modifying my sc...

Stringification on a enumeration member

Hello, I need to convert an enumeration member (its value, not the identifier) to a string. I have tried the following, which works for a MACRO (TYPE_A), but not for an enum value (typeA). This is a little bit strange in my opinion. Do you have any idea how to do this? #define _tostr(a) #a #define tostr(a) _tostr(a) typedef enum _S...

Using getchar() after read()

Hi I am using raw.c for keyboard capture. Following code finds when an arrow key/ esc is pressed. At the same time I want to read whole words that user inputs and these should be shown on stdout as well. char pp = 0; char p = 0; while( (i = read(0, &c, 1)) == 1) { if (pp == 033 && p == 0133 && (c &= 255) == 0102) /* DOWN */ break; if (c...