c

lowest and highest memory address in c?

Is there a way to print out the lowest and highest memory address that an Operating system can address in c? ...

freopen_s on stdout causes problems with GetConsoleScreenBufferInfo on Windows

To temporarily redirect stdout to a file, I'm doing: printf("Before"); freopen_s(&stream, "test.txt", "w", stdout); printf("During"); freopen_s(&stream, "CONOUT$", "w", stdout); printf("After"); That works, however doing: CONSOLE_SCREEN_BUFFER_INFO sbi = {0}; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi); No lon...

why "f = f++" is unsafe in c?

I read about 'side effect' from this website: but still not understand why f = f++ considered unsafe ? Can somebody explain? ...

Can we change the size of size_t in C?

Can we change the size of size_t in C? ...

Creating a Cocoa app using C or Perl (NOT Objective-C)

I'm having a hard time understanding how to use Cocoa with either C or Perl. Background: I've seen it mentioned in quite a few places that Mac's Cocoa API can be used with C, Perl etc. but I haven't found any information on how to go about doing this. I've also found a couple of articles saying that Cocoa can be used with Objective-C on...

How to learn C pointers?

I have worked with pointers a lot, but still whenever I work with them, I feel that one might not work the way I expect it to. My mind is not sure as to how they will behave. What do you suggest? I want to learn pointers better. ...

The intricacy of a string tokenization function in C

For brushing up my C, I'm writing some useful library code. When it came to reading text files, it's always useful to have a convenient tokenization function that does most of the heavy lifting (looping on strtok is inconvenient and dangerous). When I wrote this function, I'm amazed at its intricacy. To tell the truth, I'm almost convi...

Writing my own SMTP server

I am writing a simple SMTP server and client. Server is in two parts receiver-SMTP and Sender SMTP. both will run in two different daemon services. The two modes this can run in is 'remote' and 'local'. Since i am new to network programming I am having difficulty in even getting started. Any help in form of text, sample or skeleton code...

How to think of bit operations for simple operations?

for example: unsigned int a; // value to merge in non-masked bits unsigned int b; // value to merge in masked bits unsigned int mask; // 1 where bits from b should be selected; 0 where from a. unsigned int r; // result of (a & ~mask) | (b & mask) goes here r = a ^ ((a ^ b) & mask); merges bits from two values according to th...

Exception Handling in C - What is the use of setjmp() returning 0?

I have a few questions relating to setjmp/longjmp usage - What is the use of setjmp(jmp___buf stackVariables) returning 0. It is a default, which we cannot influence. Is the only significance of setjmp(stackVariables) is to push the stack in stackVariables. And basically 0 tells us if the stack was pushed on stack_variables success...

How to determine return address on stack ?

I know that if I am inside some fuction foo() which is called somewhere from bar() function, then this return address is pushed on stack. #include <stdio.h> void foo() { unsigned int x; printf("inside foo %x \n", &x ); } int main() { foo(); printf("in main\n")...

Running C processes in Rails

Hi there I make a call just like this: value = ./simulated_annealing Which is a C Object file, but Rails tells me it cannot find that file. I put it in the same dir that the rest of the models files (since it's called by one of those models), but I guess it should be in any other place. I've tried that outside Ruby and it works great...

Tool for program statistics

Is there a tool which is able to parse my source code (fortran, C or C++) and return statistics such as the number of loops, the average loop size, the number of functions, the number of function calls, the number, size and type of arrays, variables, etc ? Something similar to this which does not run easily on my architecture ...

StAX Writer Implementation for C/C++

Are there any other STaX Writer implementation for C/C++ except libxml2? ...

How can I test my driver is loaded, and then access my driver functions from the linux kernel?

I have a driver which compiles and loads into the linux kernel just fine. In this driver are some functions which I would like to access from the kernel file 'fs/readdir.c'. Additionally, how can I test if a driver is loaded? I need something like the following. if(myDriver is loaded){ myDriver.functionCall(); } All examples I've...

Determine if string from argv[1] starts with a character or number (C-programming)

I'm writing a small application in C that takes two parameters. One is a filename, the other a number, and they may be specified in random order. ./main filename 12345 and ./main 12345 filename should both work. How can I easily determine which is which when I know the filename starts with a character? ...

Add lines at the end of file

Hi, I would like to add logs at the end of a file for each event, and create a new one when its size up to 255 Mo. For example, the current file could be /var/log/foo.2: /var/log/foo.0.log (full log file) /var/log/foo.1.log (full log file) /var/log/foo.2.log Have you got an idea of C source to do so? Thank you ...

Is there any way to determine the available stack space at run time?

I know that stack size is fixed. So we can not store large objects on stack and we shift to dynamic allocations (e.g. malloc). Also, stack gets used when there is nesting of function calls so we avoid recursive functions as well for this reason. Is there any way at runtime to determine how much stack memory is used so far and how much is...

Copying arrays of structs in C

Hi there, It's been a long since I don't use C language, and this is driving me crazy. I have an array of structs, and I need to create a function which will copy one array to another (I need an exact copy), but I don't know how to define the function call. I guess I need to use pointers, but when I try it gives me an error. struct gro...

Why is the `gets' function is dangerous? Why should not be used?

When I try to compile C code that uses the gets function, I get a warning: warning: the gets function is dangerous and should not be used. I remember this has to do something with stack protection and security, but I'm not sure. Can someone help me with removing this warning and explain why is there such warning? If gets is "dangerous" ...