c

SQL Server: ODBC Connection pooling / C API

I want to clarify how to do connection pooling with SQL Server from C, using ODBC. I know this question is, like.... sooooo 1998, but... I've never done it in C, so... here goes: First I think I have to set the attribute to enable pooling: rc = SQLSetEnvAttr( NULL, // make process level cursor pooling SQL_ATTR_CO...

Why did this code still work?

Some old code that I just came across: MLIST * new_mlist_link() { MLIST *new_link = (MLIST * ) malloc(sizeof(MLIST)); new_link->next = NULL; new_link->mapi = NULL; new_link->result = 0; } This was being called to build a linked list, however I noticed there is no statement: return new_link; Even without the return...

How to Implement Grep into CGI script Please?

Hi all! I am having difficulty figuring out how to implement grep into my CGI script. Basically I will receive a value of eg. 1500 from a HTML page. The CGI script then runs and compares 1500 to a text file. When it finds 1500 it prints the entire line and displays it on the webpage. I would like some tips and pointers on how to do ...

Preprocessor not skipping asm directives

I'm programming to a microprocessor (Coldfire) and I don't have access every day to the microprocessor trainer so I want to be able to execute some of my code on the computer. So I'm trying to skip a part of my code when executing on the computer by defining _TEST_. It doesn't work. It tries to compile the asm code and dies whinin...

Passing pointer into function, data appears initialized in function, on return appears uninitialized

Im passing function GetCurrentDate() the pointer to a tm struct. Within that function I printf the uninitialized data, then the initialized. Expected results. However when i return the tm struct appears uninitialized. See console output bellow. What am i doing wrong? uninitialized date:??? ???-1073908332 01:9448278:-1073908376 -...

How does GetGlyphOutline function work? (WinAPI)

Basically I want to get bezier control points from a ttf font and then draw them. I was basically wondering 2 things. Does it return an array of points or is it more complex? How can you tell the points of 1 contour from another ex: the letter O which has 2 contours? Thanks ...

Stopping a runaway Lua subprocess

I have embedded Lua in an Objective-C application using LuaObjCBridge. I need to know how to stop the Lua process if it taking too much time (infinite loop?). Would running it in a separate thread help? ...

Change case of argument provided to C preprocessor macro

I'm fairly new to the C preprocessor. Is it possible to change the case of an argument provided to a function-like #define? For example, I want to write test(size) and then involve "Size" in the resulting replacement. ...

segmentation fault for the simplest program??

Hi, I am just starting out, but this piece of code is giving me a 'segmentation fault' and I can't find out what's wrong with it: #include<stdio.h> int main (void) { int number = 0; int lastDigit = 0; printf("Enter an integer: "); scanf("%d", number); number = number*10; printf("Number times ten is %d.\n", number); return...

question about static variables and extern in plain C

Is there a difference between declaring a static variable outside of a function and declaring a static variable inside a function? Also, what's the difference between declaring a variable as static and just declaring an extern variable? ...

How do you obtain a formatted date and time for the current locale in C?

What C function should I call to obtain a formatted date and time for the locale where the program is being executed? I'm asking this question because I have run into a problem using the ClamAV daemon API. The VERSION command returns the date and time of the latest virus definitions, but the code uses a call to ctime to format it. As fa...

Help translating from assembly to C

I have some code from a function subl $24, %esp movl 8(%ebp), %eax cmpl 12(%ebp), %eax Before the code is just the 'ENTER' command and afterwards there's an if statement to return 1 if ebp > eax or 0 if it's less. I'm assuming cmpl means compare, but I can't tell what the concrete values are. Can anyone tell me what's happening? ...

What does "%.6d" mean in printf

What does %.6d mean in: printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len); Is it a typo? It seems %.6d is the same as %6d. ...

How do I get uri of HTTP packet with winpcap?

Based on this article I can get all incoming packets. /* Callback function invoked by libpcap for every incoming packet */ void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) { struct tm *ltime; char timestr[16]; ip_header *ih; udp_header *uh; u_int ip_len; u_short sport,d...

How did it happen that "static" denotes a function/variable without external linkage in C and C++?

In C static can mean either a local variable or a global function/variable without external linkage. In C++ it can also mean a per-class member variable or member function. Is there any reference to how it happened that the static keyword that seems totally irrelevant to lack of external linkage is used to denote lack of external linkag...

Change the label of GtkButton

I want to be able to change the label of a GtkButton after the widget has been shown char *ButtonStance == "Connect"; GtkWidget *EntryButton = gtk_button_new_with_label(ButtonStance); gtk_box_pack_start(GTK_BOX(ButtonVbox), EntryButton, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(TopVbox), ButtonVbox, TRUE, TRUE, 0); gtk_widget_show_a...

How to write own DLL in Visual Studio, C language (not C++)

Dear all, I'm trying to create my own DLL... I used wizzard in VS2008 to create template for DLL. This works fine and the dll builds successfully (Test.dll is created). BUT, when I rename the file from Test.cpp to Test.c (which I guess causes compilation in C-mode), solution rebuilds also successfully, but no .dll is created. The list ...

Asynchronous event loop design and issues.

Hello, I'm designing event loop for asynchronous socket IO using epoll/devpoll/kqueue/poll/select (including windows-select). I have two options of performing, IO operation: Non-blocking mode, poll on EAGAIN Set socket to non-blocking mode. Read/Write to socket. If operation succeeds, post completion notification to event loop. If ...

How to convert a PGresult to custom data type with libpq (PostgreSQL)

Hi everyone! I'm using the libpq library in C to accessing my PostgreSQL database. So, when I do res = PQexec(conn, "SELECT point FROM test_point3d"); I don't know how to convert the PGresult I got to my custom data type. I know I can use the PQgetValue function, but again I don't know how to convert the returning string to my custom ...

Linux C select: piping echo to input works, but reading from keyboard doesn't?

Hi all, I am trying to understand http://beej.us/guide/bgnet/examples/select.c (included below for reference). I am doing this: :~$ cat /etc/issue Ubuntu 10.04 LTS \n \l :~$ gcc --version gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 :~$ wget http://beej.us/guide/bgnet/examples/select.c :~$ gcc select.c -o select :~$ echo "ff" | ./select...