c

What is the name of this operator: "-->"?

After reading this post on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both VS 2008 and G++ 4.4. The code: #include <stdio.h> int main() { int x = 10; while( x --> 0 ) // x goes to 0 { printf("%d ", x); } } Where in the standard is this defined, and where did it come ...

changing a program in c, so it takes an optional command line argument *infile*

Now I do have a hw question for everyone...I've been staring at this for a couple of days kind of tinkering and playing around but even with that I end up with a load of errors... What I'm trying to do is take the program below and change it so that it takes an optional command line argument infile. If infile is given, then copy infile ...

Why warning in C and can't compile in C++?

Why does this code int (*g)(int); int (*h)(char); h = g; In C, give me such warning when compiling: 'warning: assignment from incompatible pointer type' In C++, can't be able to compile. ...

How does stat() work?

stattest.c: // compile: gcc -o stattest stattest.c #include <stdio.h> #include <sys/stat.h> int main(int argc, char *argv[]) { struct stat stats; stat(argv[1], &stats); printf("%lli\n", (long long)stats.st_dev); return 0; } Usage: stat -f "%r" /dev/disk0 => 234881024 (Value that I'm looking for.) ....

Dynamic output updation on a command line interface

Hi I am eager to know how to print the output on a terminal screen similar to the one that of the 'top' command. What I mean to say is .. dynamic updation of the existing output on terminal window. A small c program or reference to appropriate resources is expected .... ...

Why Would WIFEXITED Return True on Running Process?

When I wait on a specific running process group that is a child process, WIFEXITED returns true saying the process exited? Is this the way it works? Seems there is something I am not understanding.... if ( waitpid(-pgid, &pstatus, WUNTRACED|WNOHANG ) == -1) perror("Wait error"); if ( WIFEXITED(pstatus) ) { strncpy(buf, "Exite...

typedef in c and type equivalence

If I do this: typedef int x[10]; x a; Is it same as: int a[10]; ? ...

C array initialization via macro

Hi! Question's Background: void dash(int *n, char c) is to draw characters c separated by '+'. Parameter n is an array of ints, e.g. {1, 3, 2} and '-' for c should give "+-+---+--+", which works fine. To use dash I do {int f={1, 3, 2}; dash(f, '-');}, which makes the construct copy&pastable. The question itself: To avoid copy&pasting I ...

how to set close-on-exec by default

I'm implementing a library to run commands. The library is C, on Linux. It currently does a popen() call to run a command and get output. The problem is that the command inherits all currently open file handlers. If I did a fork/exec I could close the handlers in child explicitly. But that means re-implementing popen(). Can I set clos...

How to deal with -Wconversion warnings from GCC?

I'm building my project with GCC's -Wconversion warning flag. (gcc (Debian 4.3.2-1.1) 4.3.2) on a 64bit GNU/Linux OS/Hardware. I'm finding it useful in identifying where I've mixed types or lost clarity as to which types should be used. It's not so helpful in most of the other situations which activate it's warnings and I'm asking how a...

how to make a c/c++ program run in code blocks ide?

i want to run a c program in code blocks ide but not able install the compiler to run . How to do it ? ...

Destruction of singleton in DLL

I’m trying to create a simple Win32 DLL. As interface between DLL and EXE I use C functions, but inside of DLL i use C++ singleton object. Following is an example of my DLL implementation: // MyDLLInterface.cpp file -------------------- #include "stdafx.h" #include <memory> #include "MyDLLInterface.h" class MySingleton { friend ...

Can I optimize this piece of code?

Is it possible to use any loop optimization technique here to reduce the execution time ? I need the nested loop with i and j as I need those combinations of (i,j). EDIT: even if I leave the "actual" code, with this trivial assignment, this is taking up ~5s on my Dual Core box, whereas with that actual code, it takes up ~6s. I experimen...

How to read vfat attributes of files in Linux using C

I have a FAT filesystem mounted in Linux with the vfat driver. I want to know how I would be able to read the vfat attributes of a file such as "hidden" and "read-only". Based on what I've read so far, if I use the stat() glibc command on a file, I would only be getting the file attributes listed here: http://www.gnu.org/s/libc/manua...

What is Sum of Even Terms In Fibonacci (<4million)? [Large Value Datatype Confusion]

By starting with 1 and 2, the first 10 terms of Fibonacci Series will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed 4 million. SOLVED: Actually, I managed to get the solution myself. Here's my program. It works. #include <stdio.h> int main() { int x=1,y=2...

initializing structures and nesting structures

Hello, gcc I am just getting back into c programming and I am just practicing with structures. However, I have a nested structure that I want to fill from another initialized structure. However, I don't think my technique is correct way to do this. Any advice would be most helpfull, #include <stdio.h> typedef struct { char name[20...

C #define macro for debug printing

Trying to create a macro which can be used for print debug messages when DEBUG is defined, like the following pseudo code: #define DEBUG 1 #define debug_print(args ...) if (DEBUG) fprintf(stderr, args) How is this accomplished with a macro? ...

Loading an raw image to the program and get the RGB value from each pixel in C

Hello, I want to read the RGB values for each pixel from a raw image. Can someone tell me how to achieve this? Thanks for help! the format of my raw image is .CR2 which is taken from camera. ...

How to get a variable address using a string with variables name?

I would like to do something like a simple and quick general console debugger. This small lib should be embedded to the main program. So I would like to do stuff like this while running the program in console mode: "input: print i" "output: 15.53" "input: set color 255" "input: print color" "output: 255" And both "i" and "color" wo...

Replacing FAR by nothing and PASCAL by __stdcall

I'm accessing a DLL through : int (__stdcall *Send) (char *); Send = (int (__stdcall *)(char *)) GetProcAddress(hmModule,"Send"); The original call uses: int (FAR PASCAL *Send) (char FAR *); Send = (int (FAR PASCAL *)(char FAR *))GetProcAddress(hmModule,"Send"); Is there any downside to replace FAR by nothing and PASCAL by __stdcal...