c

Why the output is printing twice?

May be it look childish for most of you but I am unable to understand this small piece of code. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char** argv) { int i, pid; pid = fork(); printf("Forking the pid: %d\n",pid); for(i =0; i<5; i++) ...

valgrind conditional jump or move depends on uninitialised value

I want to fix problem reported by valgrind: ==7182== Conditional jump or move depends on uninitialised value(s) ==7182== at 0x40EC75C: strstr (in /lib/libc-2.9.so) ==7182== by 0x804A977: search_graph_begin (compression.c:462) ==7182== by 0x804AB60: search_graph_end (compression.c:497) ==7182== by 0x804AA97: search_graph_be...

requestedExecutionLevel in manifest file and failing CopyFile() function

Just trying to copy a file using CopyFile() function from the current directory to C:\windows\system32\drivers. I wrote also manifest with "requestedExecutionLevel level="highestAvailable"" in it and I run mt to add it to resulting executable. When I try to run it, Windows 7 UAC dialog popping out, I press "Yes", but CopyFile() returni...

Unions within unions

In C, is it possible to define a union within another union? If no, why is it not possible? Or if yes, where can it be used? ...

ARM Assembly: How to pass and make use of a array of pointers inside an ARM Assembly function

Hi, I have a C function in which I have 4 pointers and each of them point to different locations of a large 2D array of floats. Because the ARM assembly functions can only be passed with 4 parameters (r0 - r3), I'm not able to understand how to pass the pointer to my return value, which will become the 5th parameter to my assembly func...

Getting the address of a triple pointer to char

Hello, gcc 4.4.4 c89 I am just wondering why I am getting different memory address. When I print the address of animals in main I get the following: animals [ rabbit ] : [ 0xbfab2e48 ] animals [ rabbit ] : [ 0xbfab2e48 ] However, when I print in the function, I get different memory locations. I think they should be the same. ptr an...

Visual Studio Changing number of bytes for data type

Is it possible to change the number of bytes a long has in visual studio? Currently when compiling C code sizeof(int) and sizeof(long) are both equal to 4. ...

Volume to physical drive

Hello, QueryDosDevice(L"E:", DeviceName, MAX_PATH); (E: is a SD card) DeviceName is "\Device\HarddiskVolume3" How do I "convert" it to something like "\\.\PHYSICALDRIVE1" ...

Partitioning struct into private and public sections?

In C++ and Java, data structures can have private, public and protected regions. I'd like to port this concept to a C language program I am writing. Are there any idioms for implementing private or protected function pointers and data fields in a C struct? I know that C structs are public, I'm looking for an idiom to help hide some i...

How do I use pointers in combination with getc?

I have a function getNum(), which gets a number from file and returns it. When I go back into getNum() I have lost the pointer and it starts at the begging of the file again. I'm wondering How do I get the location of where getc is and then go back to that place. I couldn't find how to do this in the manual or in forums. Thank you. #inc...

Trouble making a running total in C

Hi, I'm new at programming, new on this site too, so hello... I'm attempting to obtain a running total for integers one thru 10, but I'm getting gibberish answers and I just can't understand why. To attempt to find out what was going wrong, I added the printf(" running total is %d\n", sum); line to the while loop, but just got more o...

In C, How to exit a loop based on file contents

I'm attempting to exit a while loop, based on file contents. File exists and is empty, or garbage filled at initialization of the program. I externally modify the file, and would like the loop to exit upon this happening based on how the file was modified. Currently, I start a few threads, open the file that I'm reading from. Check the ...

Is there any way of preventing application from crashing when heap is corrupted? - C programing language

Hi, Sometimes in execution I get this error message in VS2010 when trying to free memory: Windows has triggered a breakpoint in [APPNAME].exe. This may be due to a corruption of the heap, which indicates a bug in [APPNAME].exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while [APPNAME].e...

Matching va_list types between compilers.

I have a project that consists of a bunch of dynamically loaded modules. Originally, everything was always built with MSVC 2003, but lately I've been working on getting it to work with GCC. Everything has been going pretty smoothly, except for one problem. For 64-bit code, GCC and MSVC don't agree about what a va_list is. For 32-bit,...

How does mprotect() work?

I was stracing some of the common commands in the linux kernel, and saw mprotect() was used a lot many times. I'm just wondering, what is the deciding factor that mprotect() uses to find out that the memory address it is setting a protection value for, is in its own address space? ...

C : Convert signed to unsigned

Hi there, Actually I've (probably) a "simple" problem. So I don't know how to cast a signed integer to an unsigned integer. My code : signed int entry = 0; printf("Decimal Number : "); scanf("%d", &entry); unsigned int uEntry= (unsigned int) entry; printf("Unsigned : %d\n", uEntry); If I send the unsigned value to the console (see...

size_t or long for the size of a string containing a file?

Suppose I want to read an entire file in memory. I'd open it in binary mode, use fseek to get to the end of the file, then do ftell to get its size. Then I would allocate a string with the same size as the file, and just read it in, right? The problem is that ftell returns a long int, and malloc should receive a size_t argument. Now, si...

string to float conversion?

I'm wondering what sort of algorithm could be used to take something like "4.72" into a float data type, equal to float x = 4.72; ...

C/C++ Checking for NULL pointer

In a recent code review, a contributor is trying to enforce that all NULL checks on pointers be performed in the following manner: int * some_ptr; // ... if( some_ptr == NULL ) { // handle null-pointer error } else { // proceed } instead of int * some_ptr; // ... if( some_ptr ) { // proceed } else { //handle null-pointer err...

Can you access the actual identifier from an enum element's numerical value?

Is there a method to return the identifier string for a given element's numerical value? For instance, logging a UITouch's phase returns an int, but having the actual string value would be easier to read. I suppose I could write my own switch statement to do this, but I'm hoping there's a built-in means. ...