c

What's your recommandation for C Unit Testing Framework ?

The framework should be as portable as possible. Thank you! Later Edit: If possible I am looking for something similar (as approach) with Java's Junit. ...

Copy results of strtok to 2 strings in C

Ok, so I have the code char *token; char *delimiter = " "; token = strtok(command, delimiter); strcpy(command, token); token = strtok(NULL, delimiter); strcpy(arguments, token); and it gives me EXC_BAD_ACCESS when i run it, and yes, command and arguments are already defined. ...

sizeof abuse : get the size of a const table

When declaring a const table, it is possible to get the size of the table using sizeof. However, once you stop using the symbol name, it does not work anymore. is there a way to have the following program output the correct size for table A, instead of 0 ? #include <stdio.h> struct mystruct { int a; short b; }; const struct my...

Char C question about encoding signed/unsigned.

Hi guys. I read that C not define if a char is signed or unsigned, and in GCC page this says that it can be signed on x86 and unsigned in PowerPPC and ARM. Okey, I'm writing a program with GLIB that define char as gchar (not more than it, only a way for standardization). My question is, what about UTF-8? It use more than an block of m...

errno returns zero always in VxWorks PPC

I am running my code on VxWorks PPC and incase of system call failures especially for socket send / recv functions, errno returns 0 always. After some analysis I found that, errno returns 0 incase of all system call failures. Is there any initialization which I should be doing for errno to return correct values? ...

How to print size_t variable portably?

I have a variable of type size_t, and I want to print it using printf(). What format specifier do I use to print it portably? In 32-bit machine, %u seems right. I compiled with g++ -g -W -Wall -Werror -ansi -pedantic, and there was no warning. But when I compile that code in 64-bit machine, it produces warning. size_t x = <something>...

Fixed-size floating point types

In the stdint.h (C99), boost/cstdint.hpp, and cstdint (C++0x) headers there is, among others, the type int32_t. Are there similar fixed-size floating point types? Something like float32_t? ...

How to encode video from multiple cameras into one mkv stream?

How to encode multiple video + audio streams (we want streams not to be any how encoded) from cameras into one mkv so, that sound from camera A is encoded with respect to wideo from camera A, using JAVA or C or C++? (algorithm should be working on different platforms eg win lin mac) ...

C Programming - My program is good enough for my assignment but I know its not good

Hi there I'm just starting an assignment for uni and it's raised a question for me. I don't understand how to return a string from a function without having a memory leak. char* trim(char* line) { int start = 0; int end = strlen(line) - 1; /* find the start position of the string */ while(isspace(line[start]) != 0) { st...

How many arguments does main() have in C/C++

Hello What numbers of arguments are used for main? What variants of main definition is possible? ...

How to define and work with an array of bits in C?

I want to create a very large array on which I write '0's and '1's. I'm trying to simulate a physical process called random sequential adsorption, where units of length 2, dimers, are deposited onto an n-dimensional lattice at a random location, without overlapping each other. The process stops when there is no more room left on the latt...

Basic C++ Speed (initialization vs adding) and comparison speed

I was curious if anyone knows which of the following executes faster (I know this seems like a weird question but I'm trying to shave as much time and resources as possible off my program.) int i=0; i+=1; or int i; i=1; and I also was curious about which comparison is faster: //given some integer i // X is some constant i < X+...

Writing code translator from Python to C?

I was asked to write a code translator that would take a Python program and produce a C program. Do you have any ideas how could I approach this problem or is it even possible? Thanks, Boda Cydo. ...

C/C++ RPC Tutorial for Linux

Can someone point me to a decent RPC tutorial for (or books) linux, like in this post. I tried looking around myself, I've only found tutorials that are really old. Thanks ...

Can I use C++ header files in kernel part of a CUDA code?

I want to compare two strings in a kernel function. Can I use strcomp in file? Generally, can I use C++ libraries in my CUDA code? ...

puts() a pointer in C

I have a function: char *make_text(void) { char txt[MAXLEN]; //make something return txt; } Thats my main program: int main(void) { char *s = make_text(); puts(s); getch(); return 0; } puts(s) returns 0 and its nothing printed. Whats happened? ...

Header correct, but identifier not found

I have two projects (x64). A. Written in C (wxWidgets) --- edit: its in C++! B. Written in C++ A compiles fine, but B (which uses functions of A) gives several errors when I try to compile. I suggest that the reason for the errors is the same for all, so I mention only the first. It says: strlen: identifier not found In the file...

Class declaration confusion - name between closing brace and semi-colon

class CRectangle { int x, y; public: void set_values (int,int); int area (void); } rect; In this example, what does 'rect' after the closing brace and between the semi-colon mean in this class definition? I'm having trouble finding a clear explanation. Also: Whatever it is, can you do it for structs too? ...

Long IF tree with strings

I have a C program which uses Lua for scripting. In order to keep readability and avoid importing several constants within the individual Lua states, I condense a large amount of functions within a simple call (such as "ObjectSet(id, "ANGLE", 45)"), by using an "action" string. To do this I have a large if tree comparing the action stri...

Moon / Lunar Phase Algorithm

Does anyone know an algorithm to either calculate the moon phase or age on a given date or find the dates for new/full moons in a given year? Googling tells me the answer is in some Astronomy book, but I don't really want to buy a whole book when I only need a single page. Update: I should have qualified my statement about googling a ...