c

Why does my c program not free memory as it should?

I have made a program in c and wanted to see, how much memory it uses and noticed, that the memory usage grows while normally using it (at launch time it uses about 250k and now it's at 1.5mb). afaik, I freed all the unused memory and after some time hours, the app uses less memory. Could it be possible, that the freed memory just goes f...

Looking for SFTP Server in Embedded Environment

I have an embedded environment with a limited amount of storage available. I want to run an SFTP server in this environment and the Linux version I'm using does not contain one. Does anyone know of a set of c-libraries for a Linux SFTP server that is lightweight? (ie. the binary is small in size, much less than 1MB) NOTE: The librarie...

My simple poll() example only partially works

I have included the code below. The program is supposed to accept telnet connections on port 8888 and then send and messages from each telnet client using poll and send and recv but It doesn't quite work 100%. It seems certain connections can always send messages to anyone and the program works fine but there is always at least one clien...

Am I correct that strcmp is equivalent (and safe) for literals?

We all know the trouble overflows can cause, and this is why strn* exist - and most of the time they make sense. However, I have seen code which uses strncmp to compare commandline parameters like so: if(... strncmp(argv[i], "--help", 6) == 0 Now, I would have thought that this is unnecessary and perhaps even dangerous (for longer par...

Variable Sized Arrays in C

On the discussion of dynamic memory here: "Intro to C Pointers and Dynamic Memory" The author states: A memory block like this can effectively be used as a more flexible array. This approach is actually much more common in real-world C programs. It's also more predictable and flexible than a "variable size array" The type of memor...

C non-blocking keyboard input

I'm trying to write a program in C (on linux) that loops until the user presses a key, but shouldn't require a keypress to continue each loop. Is there a simple way to do this? I figure I could possibly do it with select() but that seems like a lot of work. Alternatively, is there a way to catch a control-c keypress to do cleanup befor...

issue with FILE

I'm getting the folowing error for below code, "1506-221 (S) Initializer must be a valid constant expression" FILE *fp[] = {stdout, dump_f}; is this acceptable? what is the proper way to achive this? ...

Book for going from C to C++

I know C pretty well, and I need to learn C++ pretty quickly. Does anyone know of any books, that assume a decent knowledge of C, and then goes over C++? ...

Why can’t variables be declared in a switch statement?

I want to know more about "Why can’t variables be declared in a switch statement?" I read the post but i am not getting it exactly. You can just declare variable inside switch but to decalre and initialize a variable or to declare object of class it gives complie time error. Please explain me.... ...

Is there a way to use errno safely in a multi-threaded application?

If you are writing a multi-threaded application that uses system/library calls that make use of errno to indicate the error type, is there a safe way to use errno? If not, is there some other way to indicate the type of error that occurred rather than just that an error has occurred? ...

IDE for C application development that you admire most

I am looking for a good Integrated development environment for developing applictaions in C language for both windows and linux. IDE should have: good interface, easy file management, auto filling and any advanced options. Tell me which IDE you most admire for these tasks For general PC application development For embedded app...

Find out if pipe's read end is currently blocking

I'm trying to find out if a child process is waiting for user input (without parsing its output). Is it possible, in C on Unix, to determine if a pipe's read end currently has a read() call blocking? ...

What is the equivalent to Posix popen() in the Win32 API?

Is there a rough equivalent to the Linux/Unix stdio.h popen() function in the Win32 API? If so, where can I find it? Edit: I need to know this to patch an omission in the D standard library. Any answer must use only standard Win32 API, no MSVC-specific functions. Also, I'd prefer something that's not horribly low-level, if it exists...

How to work with the data in Binary in C/C++

Hello, I have to do some work work with integers, but I am interested in treat them as binary data, in a way that for example I can take the 4 most significant bits of an 32 bit value. What I am trying to do is, I have several 32 bit value I want to take for example, in the first one 4 bits, the second one 6 bits and the last one 22 bit...

How to define an object whose address is null?

I am wondering how I can define an object in C whose reference will be null? // definition of foo ... void * bar = &foo; // bar must be null There is some ways I could find to do it, but none fit my needs. __attribute__((weak)) extern int foo; //not working with cygwin/gcc 3.4 __attribute__((at(0))) int foo; //only with rvds #...

What does it mean for a char to be signed?

Given that signed and unsigned ints use the same registers, etc., and just interpret bit patterns differently, and C chars are basically just 8-bit ints, what's the difference between signed and unsigned chars in C? I understand that the signedness of char is implementation defined, and I simply can't understand how it could ever make a...

How to print out dash or dot using fprintf/printf?

As of now I'm using below line to print with out dot's fprintf( stdout, "%-40s[%d]", tag, data); I'm expecting the output would be something like following, Number of cards..................................[500] Fixed prize amount [in whole dollars]............[10] Is this a high winner prize?.....................[yes] How to prin...

Similar String algorithm

I'm looking for an algorithm, or at least theory of operation on how you would find similar text in two or more different strings... Much like the question posed here: http://stackoverflow.com/questions/246961/algorithm-to-find-similar-text, the difference being that my text strings will only ever be a handful of words. Like say I have...

Why use hex values instead of normal base 10 numbers?

I was looking over this code to calculate math.sqrt in Java. I was just wondering why they used hex values in some of the loops and as normal values for variables. What benefits are there to use hex? Thanks for your help. ...

Writing firmware: assembly or high level?

Related to: Testing firmware starting a microcontroller simulator/emulator Interpreting assembly code If you are writing code for a microcontroller is there a real difference if you write in assembly or C or some other high level language? If you wrote C code, how would you compile it? Thanks ...