Hi, in C if I have a printf statement containing say "%.2f", it says that the precision is 2 digits after the decimal place. I haven't explicitly specify the width. I have two questions:
Is this good programming practice?;
Is without specifying the width means that the width of the field will get adjusted automatically when printing th...
For a simple simulation in C, I need to generate exponential random variables. I remember reading somewhere (but I can't find it now, and I don't remember why) that using the rand() function to generate random integers in a fixed range would generate non-uniformly distributed integers. Because of this, I'm wondering if this code might ha...
Are there any high-level, cross-platform, and abstracted (simple to use) widget toolkits for C that are either very lightweight and fast or can be compiled for other toolkits, such as Qt and GTK+?
EDIT:
Most C++ libraries lack C bindings, so they will be of little (or no) help.
...
Based on sys/acct.h (V1, not V3) I need to gather some user usage statistics based on a parser that parser the acct file line by line. The parser will run and parse the entire file every N seconds and I need to gather user statistics accumulated since the last run (N seconds back). I'm not sure what will be the most appropriate way to do...
Right so i'm trying to use a C library in C++, never actually done this before i thought it would be a case of declaring the header includes under a extern "C" and setting the compile as flag to "default" but i'm still getting linker errors and think that the header file might have to be complied as a DLL. I have no idea really.
Is it ...
I am trying to write a program that will verify that all cookies sent out from the machine are in fact going to the domain they came from. This is part of a larger security project to detect cookie based malicious attacks (such as XSS). The main snag for this project is actually detecting the out-going cookies. Can someone point me in th...
So this is something that I've always wondered but was never quite sure about. So it is strictly a matter of curiosity, not a real problem.
As far as I understand, what you do something like #include <cstdlib> everything (except macros of course) are declared in the std:: namespace. Every implementation that I've ever seen does this by ...
Based on this question I understand the purpose of the construct in linking C libraries with C++ code. Now suppose the following:
I have a '.so' shared library compiled with a C++ compiler. The header has a 'typedef stuct' and a number of function declarations. If the header includes the extern "C" declaration...
#ifdef __cplusplus
ext...
Maybe I'm just not seeing it, but CRC32 seems either needlessly complicated, or insufficiently explained anywhere I could find on the web.
I understand the gist of it is that it is the remainder from a non-carry based arithmitic division of the message value, divided by the polynomial, but the actual implementation of it escapes me. I'...
C really isn't my strong point and after reading 3 chapters of a book on the subject and spending ages trying to get stuff working it just doesn't:
#include <stdio.h>
char *a,*b;
int main( )
{
char input[10];
fgets(input,sizeof input, stdin);
a = input;
fgets(input,sizeof input, stdin);
b = input;
printf("%...
Given the following code sample:
uint8_t i, in, ni;
i = in = 2; ni = 1;
while (2 == i > ni) in++;
How can I replace i, in, and ni, respectively with either in, ni, and i or inni, inin, and nini using emacs, vi, *nix commands, or anything else?
...
Hi,
I have written a program in C. Its a program created as result of a research. I want to compute exact CPU cycles which program consumes. Exact number of cycles.
Any idea how can I find that?
...
Anybody knows proper python implementation of TEA (Tiny Encryption Algorithm)? I tried the one I've found here: http://sysadminco.com/code/python-tea/ - but it does not seem to work properly.
It returns different results than other implementations in C or Java. I guess it's caused by completely different data types in python (or no data...
I was playing around with recursion and did this simple function. I was assuming that it would print out 9-0 to stdout, but, it prints 0-9. I can't see how that happens at all.
int main()
{
rec(10);
return 0;
}
int rec(int n){
if(n > 0)
printf("%d\n", rec(n -1));
return n;
}
...
I have a bit array implementation where the 0th index is the MSB of the first byte in an array, the 8th index is the MSB of the second byte, etc...
What's a fast way to find the first bit that is set in this bit array? All the related solutions I have looked up find the first least significant bit, but I need the first most significant...
I am trying to allocate a 2D dimension array of File Descriptors... So I would need something like this
fd[0][0]
fd[0][1]
I have coded so far:
void allocateMemory(int row, int col, int ***myPipes){
int i = 0,i2 = 0;
myPipes = (int**)malloc(row * sizeof(int*));
for(i = 0; i < row;i++){
myPipes[i] = (int*)ma...
Hi,
I can't understand this result...
The code:
void foo(void * key, size_t key_sz) {
HashItem *item = malloc(sizeof(HashItem));
printf("[%d]\n", (int)key);
...
item->key = malloc(key_sz);
memcpy(item->key, key, key_sz);
}
void bar(int num) {
foo(&num, sizeof(int));
}
And I do this call: bar(900011009);
...
Hey hey,
I am working on a little mini compiler while trying to learn some MIPS here. Here's my issue:
MIPS has an instruction li (load immediate) which would work like this
li $5,100
which would load 100 into register 5.
However, I need to load floats into registers right now and am struggling with figuring out a way to do it...s...
Hi everybody, I'm having the above error request member rv in something not a structure of union. I've googled it and several answers told me it's when working with a pointer but tries to access it as a struct, where I should be using -> instead of .
int foo(void * arg, struct message * msg)
{
struct fd_info * info = (struct som...
Here's my C method to get the pid of the Finder process. GetProcessInformation() is causing a segfault. Why?
Here's the function:
static OSStatus
GetFinderPID(pid_t *pid)
{
ProcessSerialNumber psn = {kNoProcess, kNoProcess};
ProcessInfoRec info;
OSStatus status = noErr;
info.processInfoLength = sizeof(ProcessInfoRec);
...