c

strcpy when dest buffer is smaller than src buffer

I am trying to understand the difference/disadvantages of strcpy and strncpy. Can somebody please help: void main() { char src[] = "this is a long string"; char dest[5]; strcpy(dest,src) ; printf("%s \n", dest); printf("%s \n", src); } The output is: this is a long string a long string QUESTION: I dont understand, how the sou...

In Windows, how can one create a child process and capture its stdin, stdout, and stderr, without duplicating any inheritable handles?

There are at least three parts to this problem, so bear with me: 1) CreateProcess has a parameter bInheritHandles, that causes the child process to inherit all of the inheritable handles in the parent process. This option must be set to TRUE to allow the parent to specify stdin, stdout, and stderr handles for the child in the STARTUPINF...

Don't expose symbols from a used library in own static library

I am writing a reusable static library for the iPhone, following the directions provided here. I want to use minizip in my library internally, but don't want to expose it to the user. It should be possible for the user to include minizip themselves, possibly a different version, and not cause clashes with my "inner" minizip version. I...

String substitution using tcl API

Is there a way to (ab)use the tcl C-API to 'parse' a string, doing all the replacement (including sub commands in square brackets), but stopping before actually evaluating the resulting command line? What I'm trying to do is create a command (in C, but I'll consider doing a tcl-wrapper, if there's an elegant way to do it there) which ta...

Pass format string through procedure to fprintf

I'm working on a program that generates an FDF file for filling in an Adobe PDF form. Currently, I have various procedures that are called, as before each one terminates, it opens the FDF file, writes its particular data, and closes the file. I'm trying to put the code for writing the data to the FDF file in a separate procedure, and th...

Pointer stability under Windows Vista

I have been using Visual Studio 2005 under Windows XP Pro 64-bit for C and C++ projects for a while. One of the popular tricks I have been using from time to time in the debugger was to remember a numeric pointer value from the previous debugging run of the program (say 0x00000000FFAB8938), add it to watch window with a proper typecast (...

How to write a linker.

I have written a compiler for C that outputs byte code. The reason for this was to be able to write applications for an embedded platform that runs on multiple platforms. I have the compiler and the assembler. I need to write a linker, and am stuck. The object format is a custom one, designed around the byte code interpreter, so I ca...

Obtain the domain name on a workstation or server

Some systems don't have a domain name configured or they might have something in the form of domain.local; yet they are located within a domain. Is there a way to get the domain these system belong to? I already tried using the classic APIs: NetWkstaGetInfo() DnsQueryConfig() and many others... Code is appreciated. ...

Close a FILE pointer without closing the underlying file descriptor

By using fdopen(), fileno() it's possible to open streams with existing file descriptors. However the proper way to close a file, once you've opened it with a stream is to fclose() the FILE pointer. How can one close the stream, but retain the open file descriptor? This behaviour is akin to calling fflush() and then fileno(), and then n...

What could cause a Labwindows/CVI C program to hate the number 2573?

Using Windows So I'm reading from a binary file a list of unsigned int data values. The file contains a number of datasets listed sequentially. Here's the function to read a single dataset from a char* pointing to the start of it: function read_dataset(char* stream, t_dataset *dataset){ //...some init, including setting dataset...

Shift Left Logical <<

How exactly do I do this in C/C++? Let's say I want to shift int i twice to the left and store the value in f. f = i << 2 ? I don't need this for a program or anything, I'm just interested in how it works. Thanks. ...

[MIPS] How is lw represented in C or C++?

So, for example, what would something like this: lw $t1, 0($t0) or lw $t2, 8($t0) Translate to in C or C++? I mean I'm loading a word from the address into a register, I get that. Is an array a similar concept, or, what? Thanks in advance. ...

cosf(M_PI_2) not returning zero

This started suddenly today morning. Original lines were this float angle = (x+90)*(M_PI/180.0); float xx = cosf(angle); float yy = sinf(angle); After putting a breakpoint and hovering cursor.. I get the correct answer for yy as 1. but xx is NOT zero. I tried with cosf(M_PI_2); still no luck.. it was working fine till yesterday.. I ...

Writing expressions: Infix, Postfix and Prefix

Greetings, My task is to write an app(unfortunatly on C) which reads expression in infix notation(with variables, unary and binary operators) and store it in memory, then evaluate it. Also, checks for correctness should be performed. for example: 3*(A+B)-(-2-78)2+(0A) After I got all values, program should calculate it. The ques...

opnecv tracking dots

hi i want to put dots to cordinates to a video frame which i determine and track them like opencv sample "lk demo" i didnt understand the sample. which functions put the dots and track them thanks for suggestions /* Demo of modified Lucas-Kanade optical flow algorithm. See the printf below */ #ifdef _CH_ #pragma package <openc...

#include directive: diff between "test.h" and "./test.h"

Is there any difference between #include "./test.h" and #include "test.h" for C/C++ preprocessor? ...

is this a good way to do a strcmp to return false when strings are empty

I want another condition --still maintaining a fast execution time but safer-- where i return false if either or both strings is empty: int speicial_strcmp(char *str1, char* str2 ) { if(*str1==*str2 =='\0') return 0; return strcmp(str1,str2); } ...

Viewing data in a circular buffer in real-time

I have an incoming stream of messages, and want a window that allows the user to scroll through the messages. This is my current thinking: Incoming messages go into single producer single consumer queue A thread reads them out and places them into a circular buffer with a sequential id This way I could have multiple incoming streams s...

Why is a type qualifier on a return type meaningless?

Say I have this example: char const * const foo( ){ /* which is initialized to const char * const */ return str; } What is the right way to do it to avoid the compiler warning "type qualifier on return type is meaningless"? ...

warning #411: class foo defines no constructor to initialize the following:

I have some legacy code built with c++ compiler giving the error in the subject line typedef struct foo { char const * const str; } Foo; and a lot of places in the code (meaning I cannot change all of them) use it in a C style initialization: Foo arr[] ={ {"death"}, {"turture"}, {"kill"} } What is the good wo...