c

Howto Generalize SSCANF and #DEFINE in C programming

The code below tries to parse a file containing these 3 lines: 0 2 5 9 10 12 0 1 0 2 4 1 2 3 4 2 1 4 2 3 3 -1 4 4 -3 1 2 2 6 1 and stores them in these arrays: int Line1[] = { 0, 2, 5, 9, 10, 12 }; int Line2[] = { 0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4 }; double Line3[] = { 2, 3, 3, -1, 4, 4, -3, 1, 2, 2, 6, 1 }; However in p...

More fine-grained behavior of gcc -Wshadow option

Folks, I really like the -Wshadow option since it helps to spot some possible problematic pieces of code. I want to use it in a really large project but I can't since it's too strict. For example it throws a warning for the following case: struct Foo { Foo(int info) : info_(info) {} //shadow warning is here void info(){ ... } int ...

Two basic question about compiling and libraries

I have two semi-related questions. My first question: I can call functions in the standard library without compiling the entire library by just: #include <stdio.h> How would I go about doing the same thing with my header files? Just "including" my plaintext header files obviously does not work. #include "nameofmyheader.h" Basica...

Passing a constant matrix

Referring to this question and especially the accepted answer of litb, I wonder why the gcc complain about this: void func(const int (*ip)[3]) { printf("Value: %d\n", ip[1][1]); } int main() { int i[3][3] = { {0, 1, 2} , {3, 4, 5}, {6, 7, 8} }; func(i); return 0; } If I eliminate the const the compiler keeps still. Di...

How to convert char * to unsigned int in C programming in win32

Hi I am trying to convert char *str = "10.20.30.40" ; in to unsigned int . can u pls tell me any method is there or any sample code . pls share me. ...

What's up with "GetStockObject" ?

I've created a program in Eclipse / MinGW / C (project type: C) which should just present an empty window. It also has the folowing line: wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); The call to GetStockObject() produces a compiler error: Z:/mtsts_workspace/MTSTS/Debug/../WinMain.c:29: undefined reference to ...

How to read a string of length 'n' from Standard input

I would like to know how to read a string from Standard input of length 'n'. I tried out using fgets() function but had a problem if I submit a string of length > n #include <stdio.h> int STRING_SIZE=4; int getString(char *); int getString(char *str) { printf("\nEnter a string of length < %d: ", STRING_SIZE); fgets(str, STRING_S...

Memory leak when calling java code from C using JNI

Hi, I have a C program that stores some object in java store using JNI. (Before someone ask, using java store is a requirment here and I have to write a client in C which would be able to add and retrieve objects from this store). I made the program and tried to add 100000 object of size 1KB. But after adding only 50000 objects I am get...

Print n levels of callstack?

Using C++ with Visual Studio, I was wondering if there's an API that will print the callstack for me. Preferably, I'd like to print a callstack 5 levels deep. Does windows provide a simple API to allow me to do this? ...

Help gcc to not warn about not using a string literal format string

I'm creating a function in C to convert an index value into a string, which is a verbose description of the "field" represented by the index. So, I have a nice array with all the verbose descriptions indexed by, well the index. To dump it into a buffer I use code like this #define BUFFER_SIZE 40 void format_verbose(uint32_t my_index, ...

*nix select and exceptfds/errorfds semantics

The select() syscall takes 3 filedescriptor sets for watching fds for readable/writeable and "exceptions" on filedescriptor. My select man page doesn't state much about the exceptfd descriptor set. What is it used for - what kind of exceptions can and will it notify on file descriptors ? I'm assuming this can be different for the descr...

qsort crashing program - C

Trying to follow this example. (Section String sorting...) Is there anything obvious that would make this crash in stdlib's qsort.c? I also tried *cstring_cmp* with strncmp specifying 30 chars max, much more than I have. *fileArray[20] seems to be correctly populated with strings. Thanks. char* ptr_fileName; char* fileArray[20];//num...

Serial Port Redirection or Splitting

I am looking for a book and or a code sample of how to do serial port redirection or port splitting. I write a lot of com port applications and want to write a monitor application that will allow me to watch the serial port between the application and the device. So I want to be able to redirect the serial port to another port so I can...

mkfifo file permissions not being executed correctly

The following line in my C program should provided All/Group/Owner read and write permissions mkfifo("/tmp/dumbPipe", 0666) But once I execute the code and check out the permission non of the write bits were set, I end up with prw-r--r-- The owners are the same, Is it a problem since I'm creating the pipe in the tmp directory? When...

where is c function attribute set (how to unset) with gcc

I am working with code from the GNU core utils, and find that the void usage() function is apparently set with the attribute "noreturn". Well, I am modifying the function, and I wish it to return (I removed the call to exit()). The compiler still complains that a "noreturn" function returns, and when using the Eclipse CDT debugger, ste...

Open DOS window and spew debug messages from DLL

I am currently calling a DLL from labview, but I need to be able to debug it realtime (because of it's accessing time sensitive hardware). I would like to just printf() my error assert messages but I am unsure about how to open a DOS window from within the DLL to dump error information to. Has anyone done this before? I know I could do t...

When debugging on Windows where does stderr go?

When trying to debug a program on Windows I can't seem to find where the output I push to stderr is going. How do I get a hold of my stderr output? Is there a debugger-level setting (MSVC 9) I can change to redirect stderr to some part of the UI? Update: I have not looked into TRACE or OutputDebugString, but the code base is cross-platf...

Checking if a registry key exists

I am looking for a clean way to check if a registry key exists. I had assumed that RegOpenKey would fail if I tried to open a key that didn't exist, but it doesn't. I could use string processing to find and open the parent key of the one I'm looking for, and then enumerating the subkeys of that key to find out if the one I'm interested ...

Confused by Unresolved external symbol error

I'm trying to build a wrapper library with VC++'s compiler. ErlDriver.c #define __WIN32__ #define DLL_EXPORT __declspec(dllexport) #include "erl_driver.h" DLL_EXPORT int _driver_output(ErlDrvPort port, char *buf, int len) { return driver_output(port, buf, len); } build.bat cl /I%ERL_DRIVER_H% /LD /MD ErlDriver.c When I attem...

Natural sort in C - "array of strings, containing numbers and letters"

Looking for a proven to work algorithm for production. Did see this example but not finding much else on the web or in books. i.e. file_10.txt > file_2.txt Thanks. ...