c

What is a good project for starters with some actual use

I wont call myself a novice programmer, I have been working for a while now in c and c++ however I have never worked on something of my own. I think a bigger learning can be accomplished if one works on some project on there own apart from there work. Keeping this in mind, could you guys tell me some project I can implement? I recently l...

After malloc, how to obtain more memory that is still continuous?

This is an interview question. If you use malloc to get a piece of memory, such as: char *p = (char *) malloc (100); Now you find you need more memory, say 130. How to obtain the memory such that the new piece of memory is still continuous ...

kernel function parameter as const

say I have a kernel foo(int a, int b) { __shared__ int array[a]; } it seems a has to be a constant value, I added const in front of int. It sill didn't work out, any idea? foo(const int a, const int b) { __shared__ int array[a]; } ...

how to use gdb to explore the stack/heap?

Hello. Could anyone please give me a quick overview/point me to documentation of a way to inspect the stack (and heap?) of a C program? I thought this should be done with GDB, but if there are other more straighforward alternatives, then that should be fine as well. Thanks. ...

How to debug win 32 process to find memory access violation?

I have Agent installed on remote machine, this agent behave like process works in background, the process open socket connection with port number. The problem: this agent was exploited by security company, I am as QA want to find the problem for fix it. I have Perl script that able to connect to the agent by socket connection and send so...

-std=c99 wtf on Linux

When I try to compile this on Linux with -std=c99 gcc complains about not knowing struct timespec. However if I compile this w/o -std=c99 everything works fine. #include <time.h> void blah(struct timespec asdf) {} int main() { struct timespec asdf; return 0; } Why is this and is there a way to still get it to work with -std=c99?...

SDL: Is this safe to do in a multi-threaded program?

I have a thread that does the following: Initializes SDL Stores a pointer to the SDL_Surface Goes into a loop and waits for any mouse events and processes them In another thread there is a function that does the following: Gets the pointer to the SDL_Surface Does a SDL_LockSurface Manipulates the pixels Does a SDL_UnlockSurface Ca...

In regards to for(), why use i++ rather than ++i?

Perhaps it doesn't matter to the compiler once it optimizes, but in C/C++, I see most people make a for loop in the form of: for (i = 0; i < arr.length; i++) where the incrementing is done with the post fix ++. I get the difference between the two forms. i++ returns the current value of i, but then adds 1 to i on the quiet. ++i first ...

lookup table in c

Hi, I'm creating a lookup table in C When I define this: typedef struct { char* action; char* message; } lookuptab; lookuptab tab[] = { {"aa","bb"}, {"cc","dd"} }; it compiles without errors but when I do something like this: typedef struct { char* action; char* message[]; } lookuptab; lookuptab tab[] = { {"aaa", {"bbbb"...

C: working with char array as 8 byte blocks

Hi, I have an array of chars and a pointer to it. I need to add the first 8Bytes (binary value of the 8 Bytes) to the second 8 bytes modulo 2exp(64). How could I do that? I found a solution. But it is definitely not good to do such things (see the code). Nevertheless it would be nice to have the result in chars array. void init(const u...

Canonical example of stack destruction in a C program

Hi, could someone please teach me a common example whereby (!) you destroy the stack in a C program? I use GCC, in Ubuntu. Thanks. ...

system() to c++ without calling cmd.exe

how can I run system("") without showing cmd.exe? I use cstdlib header code::blocks 10.5 I saw this question for c# but I don't know c# ;) ...

C, flushing stdin

Hi, i have a problem with the use of fgets. The loop is supposed to read a line of max. 19 characters, analyze this char array and then wait for next input. The problem is that if the line entered exeeds 19 characters, fgets will fill str with the remaining characters untill Ctrl-D or newline is entered, thus initiating a new loop withou...

Binary Tree in C - Troubles

typedef struct node { struct node *leftChild, *rightChild; int value; } bst; void insert(bst* b, int i) { b=malloc(sizeof(b)); b->value=i; b->leftChild = NULL; b->rightChild = NULL; printf("[%i]",b->value); return; } main() { bst* b...

Problem with running c program on mac?

Hi guys. I'm a total beginner in C programming so please bear with me. I have just started today and wanted to write a short program - well at least a small script that would just print out a line of text. Now here's what I did in order to achieve this: I downloaded vim text editor and wrote this few lines of code: #include <stdio.h> i...

open64() fails with ENOENT, even though the file exists

I'm trying to open a file that I just created with open64(). When I try to open the file though, the syscall fails with ENOENT. I know for a fact the file exists, because I just created it and ls shows it in the directory it is supposed to be in. When I try to open it with open(), it fails with EOVERFLOW, which is expected, but it also i...

Loop-Tiling to Rotate a Matrix

I'm trying to write a function to rotate an image matrix using the loop-tiling technique. However, I'm running into some issues with getting it to work properly. EDIT: Here's my updated code that works, but only when n is a multiple of the block size. How would I go about handling varying matrix sizes? Right now, I'm just using square ...

how to randomly print 1 to 10 in C

Possible Duplicates: Generate Random numbers uniformly over entire range In C, how do I get a specific range of numbers from rand()? i want to generate random number in C. It has rand() and srand() function in stdlib.h But it gives me very large number. But I want only number b/w 1 to 10. So, is it possible and if yes then h...

Working around the char array on stack align problem

See: http://stackoverflow.com/questions/3874615/placement-new-issue Simple question, would this solve the align problem? union { char real_array[sizeof(T)*size]; T fake_array[size]; }; ...

How to reset an object's security descriptor to the default?

As part of a testing utility I am creating some registry keys and applying a specific security descriptor to them. Later on I want to reset it to the "default" security descriptor (i.e. inherited from the parent). What is the proper way to do this? I can't save and restore the original security descriptor because this utility may be r...