c

Where is stdbool.h?

I want to find the _Bool definition on my system, so for systems where it's missing I can implement it. I've seen various definitions for it here and on other sites, but wanted to check on the system for the definitive definition. Slight problem, in that I can't find where _Bool is defined or even stdbool.h mussys@debmus:~$ find /usr/i...

XOR on a very big file

I would like to XOR a very big file (~50 Go). More precisely, I would like to do so by XORing each block of 32 bytes of a plaintext file (because of lack of memory) with the key 3847611839 and create (block after block) a new cipher file. Thank You for any help!! ...

Codeblocks on fedora 9 : Cannot build the C project

I have a simple C console application named Test. But when I build, it says Test - Debug uses a invalid compiler Nothing to do What is the error? The test.cbp(project file) contents are as follows: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_project_file> <FileVersion major="1" minor="6" /> <Pr...

Is there a way to get text as soon as possible without waiting for a newline?

I'm using C. I wrote a very simpe program which prints back the input, using getchar() and putchar() or printf(). Is there any way to make it so as soon as the user types one key, the program registers it, without waiting for an Enter? Let me show: Currently, if the user types "abc" and then presses Enter, the program prints "abc" and a...

How do I use the C date and time functions on UNIX?

Jon Skeet spoke of the complexity of programming dates and times at the 2009 DevDays in London. Can you give me an introduction to the ANSI C date/time functions on UNIX and indicate some of the deeper issues I should also consider when using dates and times? ...

128-bit type error

Hi, Thanks to pbos help and its program (published here, for xoring a big file), I performed some tests and I see that I have another problem: having changed the mask by another one of 128-bit, there is no default type as big as needed. I think a solution can be to include a library to increase available integer types... but rather tha...

How are C++-style comments handled in GCC 4.3.3 by default?

I'm using GCC 4.3.3 on Ubuntu 9.04 64-bit and was getting errors using C++-style comments in C code. When I say "by default" in the title, I mean simply invoking gcc test.c According to the GCC 4.3.3 docs (here), this is supported...yet I got the errors anyway. These errors went away with a simple -std=c99 addition to my compile string...

how does this array indexing work?

I'm trying to understand how this exactly works (I know what it does, I just don't understand how). As far as I know, this reads a char until EOF is reached, and if its a digit, put it in the array: while ((c = getchar()) != EOF) if (c >= '0' && c <= '9') ++ndigit[c-'0']; I understand I can index an array like this: some_array[...

Can I use C++ libraries in a C program?

I am writing a program in C, but I would like to use dynamic libraries like a vector. Is it possible to use C++ libraries in a C program? ...

Examining code generated by the Visual Studio C++ compiler, part 1

Background I'm just learning x86 asm by examining the binary code generated by the compiler. Code compiled using the C++ compiler in Visual Studio 2010 beta 2. Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.21003.01 for 80x86 C code (sandbox.c) int mainCRTStartup() { int x=5;int y=1024; while(x) { x--; y/=2; }...

Array of buffers in C programming?

I am trying to create an array of buffers. I need to store an integer into each buffer. I'm not quite sure how this should be done. int BUFFER_LENGTH = 50; //the size of each buffer int numberOfBuffers = 10; //number of buffers int *pBuffers; //array of buffers pBuffers = (int *) calloc (numberOfBuffers, sizeof(int)); /...

Help With K&Rs Counting Chars Example

I'm working my way through K&R's 2nd edition, and I've been stumped with this seemingly simple example: #include <stdio.h> main(){ double c; for(c = 0; ((getchar() != EOF) && (getchar() != '\n')); ++c) ; printf("%.0f\n",c); } It simply isn't working correctly. I added in the (getchar() != '\n') portion to end the...

C fopen vs open

Is there any reason (other than syntactic ones) that you'd want to use FILE *fdopen(int fd, const char *mode); or FILE *fopen(const char *path, const char *mode); instead of int open(const char *pathname, int flags, mode_t mode); when using C in a Linux environment? ...

Load numbers from text file in C

Hi everyone, I'm wanting to load a known number of numbers into an array in C from a text file (.txt). The format would be: "0,1,2,5,4" I'm kinda new to C, can anyone recommend a way to load in the text file? Cheers ...

C Memory Allocation: Why there is not enough memory(250K only)

Hi, I am having trouble figuring out the reason why my .c code is having trouble allocating ~250K of memory. Here is the allocation code: struct IMAGE { int width, height, maxval; char **data; }; void raiseError(char *msg) { printf("%s", msg); getch(); exit(1); } //... IMAGE readPGM() { IMAGE image; image....

C: const vs no const ..how come this compiles?

I have a simple C function which I declare as: int strLen(const char* str_) { str_ = (char*) 0; return 0; } I was very surprised that that compiles! Why is that? Whereas this onedoesn't compile (which makes sense): int str(const int i_) { i_ = 0; return 0; } ...

dbus: flush connection?

When I do a "dbus_connection_close", do I need to flush the message queue? In other words, do I need to continue with "dbus_connection_read_write_dispatch" until I receive the "disconnected" indication or is it safe to stop dispatching? Updated: I need to close the connection to DBus in a clean manner. From reading the documentation, a...

How does call by value and call by reference work in C?

In a C program, how does function call by value work, and how does call by reference work, and how do you return a value? ...

How to get large file size using c

I need to get the size of files. These files range in size from very small to 10's of gigabytes. Are there any c functions that work in both linux and windows to do this? I've seen fileinfo64 but that seems to be windows only and i haven't been able to determine the maximum size supported by stat. ...

Recompiling same code produces different executable in VC++

I developed a Windows command line tool using C, and compiled it in VC++, sometimes back, and checked-in the source code. I cleaned the project before checking-in, which deleted the .exe , .obj files besides others. I continued to use the command line tool though. After a couple of months, I checked out the source, compiled again, but t...