c

What is a simple and reliable C library for working with Excel files?

Well... that's it. I need something simple and reliable (doesn't have to have fancy features - I need to write and read text and numbers from Excel cells) And yes, I would like a sample "Hello Cell" code... What do you recommend? ...

Sqlite C user defined function

I'm using the sqlite C API. "Everything" is run in the main function (variables, open, execute a query, close the database, etc.) In addition, I would like to now create separate user defined functions where I do, for example, a sort on the database. What is the best method to pass the db objects and variables from main to this new fu...

Why no compiler error?

I'm working on a C-brain teaser: Write the standard Hello-World program, without semi-colons. My best answer so far is: int main(void) { if (printf("Hello World!\n"), exit(0), true) { /* do nothing */ } } But I don't understand why I don't get compiler error (Visual Studio): error C4716: 'main' : must return a v...

Should I use GetProcAddress or just include various win32 libraries?

Wonder what the difference between: static PROCESSWALK pProcess32First=(PROCESSWALK)GetProcAddress(hKernel,"Process32First"); ... pProcess32First(...); and #include <Tlhelp32.h> ... Process32First(...); What are the differences, I wonder which I should use. Is there any difference in terms of best practices then? ...

fread example from C++ Reference

I often use the website www.cplusplus.com as a reference when writing C code. I was reading the example cited on the page for fread and had a question. As an example they post: /* fread example: read a complete file */ #include <stdio.h> #include <stdlib.h> int main () { FILE * pFile; long lSize; char * buffer; size_t result;...

What do you use to unit test C code?

I am a professional web developer and therefore I'm used to using very high-level scripting languages and testing tools. I've recently been working, personally, more with C and writing many C programs for unix-based systems to do various tasks. However, I still haven't gotten into a good groove for unit testing this code and I was wonde...

How can the Linux kernel compile itself?

I don't quite understand the compiling process of the Linux kernel when I install a Linux system on my machine. Here are some things that confused me: The kernel is written in C, however how did the kernel get compiled without a compiler installed? If the C compiler is installed on my machine before the kernel is compiled, how can th...

Semantics of char a[]

I recently embarrassed myself while explaining to a colleague why char a[100]; scanf("%s", &a); // notice a & in front of 'a' is very bad and that the slightly better way to do it is: char a[100]; scanf("%s", a); // notice no & in front of 'a' Ok. For everybody getting ready to tell me why scanf should not be used anyway for securi...

Help with custom getline() function

Can anyone explain to me why this isn't working? #include <stdio.h> #include <stdlib.h> char *getline(int lim) { char c; int i; char *line; line = malloc(sizeof(char) * lim); i = 0; while((c = getchar()) != '\n' && c != EOF && i < lim-1) { *line = c; line++; i++; } *line = '...

How to correctly use the extern keword in c.

My question is about when a function should be referenced with the extern keyword in c. I am failing to see when this should be used in practice. As I am writing a program all of the functions that I use are made available through the header files I have included. So why would it be useful to extern to get access to something that was...

Is it acceptable not to deallocate memory

I'm working on a project that is supposed to be used from the command line with the following syntax: program-name input-file The program is supposed to process the input, compute some stuff and spit out results on stdout. My language of choice is C++ for several reasons I'm not willing to debate. The computation phase will be highly...

Is there a function to round a float in C or do I need to write my own?

Is there a function to round a float in C or do I need to write my own? float conver= 45.592346543; Would like to round actual value to one decimal place. conver = 45.6 Thanks. ...

How can I access a variable in a calling application from a dll?

I'm trying a little concept test to change one of the features of the logitech MS3200 keyboard (the zoom feature). I've got the keys that are sent from the zoom control. So, I have a main app, and a dll that contains a hook procedure. Here's the main app: #include <stdio.h> #include <windows.h> HANDLE hHook; int main() { HINSTAN...

[C/C++] double to hex string & hex string to double

Hi, What I'm trying to do is to convert a double to hex string and then back to double. The following code does conversion double-to-hex string. char * double2HexString(double a) { char *buf = new char[17]; // double is 8-byte long, so we have 2*8 + terminating \0 char *d2c; d2c = (char *) &a; char *n = buf; int i; f...

Creating a FIFO queue in C

Is it possible to create a FIFO 'stack' in C without using 2 stacks? Thanks! (Sorry to those who answered the previous one. I was thinking LIFO and meaning FIFO.) ...

How can I simulate key presses to any currently focused window?

I am trying to change the keys my keyboard sends to applications. I've already created a global hook and can prevent the keys I want, but I want to now send a new key in place. Here's my hook proc: LRESULT __declspec (dllexport) HookProc(int nCode, WPARAM wParam, LPARAM lParam) { int ret; if(nCode < 0) { return CallNex...

Why would anybody use C over C++?

Although people seem to like to complain about C++, I haven't been able to find much evidence as to why you would want to choose C over C++. C doesn't seem to get nearly as much flak and if C++ has all these problems why can't you just restrict yourself to the C subset? What are your thoughts/experience? Exact Duplicate: What's the ad...

When you were learning C in the K&R - did you do all the exercises?

I have this problem where if I read a book such as the K&R, I become fearful that I haven't learnt enough, until I've done all the exercises it asks of me; The K&R is a difficult book to many (C is a first language here), did you do and complete all exercises in the book? And if you didn't, are they all necessary in becoming competent ...

Pass arguments into C program from command line.

So I'm in Linux and I want to have a program accept arguments when you execute it from the command line. For example, ./myprogram 42 -b -s So then the program would store that number 42 as an int and execute certain parts of code depending on what arguments it gets like -b or -s. ...

Native vs. Protothreads, what is easier?

I just stumbled on Protothreads. They seems superior to native threads since context switch are explicit. My question is. Makes this multi-threaded programming an easy task again? (I think so. But have I missed something?) ...