As the title says, I need to write a small program to read data from standard input, sort it, and send it to standard output. The program should take 1 argument that tells it how long is one record (in bytes). Here's how I test it:
printf 'D\x00C\x00\x00B\x00A' | ./binsort 2 | od -c
The above should output something like:
0000000 \0...
For my Programming 102 class we are asked to deliver C code that compiles and runs under Linux. I don't have enough spare space on my hard drive to install Linux alongside Windows, and so I use cygwin to compile my programs.
The most recent program I had to give in compiles and runs fine under cygwin. It compiles fine under Linux, but h...
I am interested in writing utf-8 encoded strings to a file.
I did this with low level functions open() and write().
In the first place I set the locale to a utf-8 aware character set with
setlocale("LC_ALL", "de_DE.utf8").
But the resulting file does not contain utf-8 characters, only iso8859 encoded umlauts. What am I doing wrong?
Add...
I was looking through some code from the SDL library and came across a function declared like this:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Now, I'm a Delphi coder. No hablo C muy bien, senor. But I remember enough syntax from my college courses to read it like this:
Function name is WndProc. Ar...
I'm fairly new to programming but I've been reading some interesting discussions on StackOverflow about various programming approaches. I'm still not 100% clear on what the difference is between procedural programming and object oriented programming. It sounds like object oriented programming still uses procedures (methods) but everythin...
Hey all. I want to use print to print hex numbers in the form 0x###, but if the number is 0, I want to omit the 0x part. How can I do this?
Thanks!
...
Inspired by the question Difference in initalizing and zeroing an array in c/c++ ?, I decided to actually examine the assembly of, in my case, an optimized release build for Windows Mobile Professional (ARM processor, from the Microsoft Optimizing Compiler). What I found was somewhat surprising, and I wonder if someone can shed some ligh...
Could someone please explain me how extra functionality is added to C?
For example, C has no output function, so you can use printf() by including stdio.h, C doesn't know how to open a MessageBox so you include and use MessageBox() etc.
But how is this functionality implemented?
Do you have to use assembler in some way and access the...
I'm creating a game in OpenGL which loads the entire Arial Unicode MS font when it loads. The program uses on avg. 10 megs of memory on my computer (op sys is WinXP SP2) and runs without problems, but when I move the program to my laptop (with Vista) the wglUseFontBitmaps hangs and allocates memory fluently and never returns. This proble...
Hi,
I'm trying to configure emacs to indent my C block comments nicely.
Emacs (22.3) does by default (regardless of the indentation style):
/* My very long comment which spreads over multiple lines
* and thus needs to be filled.
*/
But what I would highly prefer is:
/* My very long comment which spreads over multiple lines
* and...
Calling a Lua function from C is fairly straight forward but is there a way to store a Lua function somewhere for later use? I want to store user defined Lua functions passed to my C function for use on events, similar to how the Connect function works in wxLua.
...
Does the Win32 API have a function for joining two paths?
I can't find it, so I thought I'd ask before rolling my own.
...
In C you can have external static variables that are viewable every where in the file, while internal static variables are only visible in the function but is persistent
For example:
#include <stdio.h>
void foo_bar( void )
{
static counter = 0;
printf("counter is %d\n", counter);
counter++;
}
int main( void )
{...
I'd like to test a function that takes runtime-allocated multidimensional arrays, by passing it a hardcoded array.
The function has a signature of void generate_all_paths(int** maze, int size) and the array is defined as int arr[5][5] = {REMOVED}.
I'm not exactly sure how to properly coerce the array for the function (or if that is imp...
Hi All,
Can someone help me with the getopt fuction?
When i do the following in main:
char *argv1[] = {"testexec","-?"};
char *argv2[] = {"testexec","-m","arg1"};
int cOption;
/* test for -? */
setvbuf(stdout,(char*)NULL,_IONBF,0);
printf("\n argv1 ");
while (( cOption = getopt (2, argv1, "m:t:n:fs?")) != -1) {
switch(cOption){
...
I'm working on a thread library which implement user level threads (i have something like pthread_setscope which works) and I'm looking for some set of tests to avoid writing one for every function I implement (mutexes, conditions, etc ...)
Does anyone know something like that?
...
I'm trying to make a XSLT conversion that generates C code, the following XML should be converted:
<enum name="anenum">
<enumValue name="a"/>
<enumValue name="b"/>
<enumValue name="c" data="10"/>
<enumValue name="d" />
<enumValue name="e" />
</enum>
It should convert to some C code as following:
enum anenum {
a = 0,
b...
If i have a string formatting program in C, that consits of only one file, is it possible to find where that file resides in memory and let the running program process its own source file? In other words, when a C program runs, is it possible to define a pointer that points to the actual code, and process that? Not sure if that makes sen...
Hi,
I'm actually writing an MPI program. This is a basic client / server pattern. The server have a set of work to compute. The clients get subsets of this big set. Each client use several threads to compute the subset. I must be sure all the threads finished before requesting another subset to the server.
The client is split into seve...
Is there a way to have some kind of default constructor (like C++ one) for C user types defined with a structure?
I already have a macro which works like fast initializer (like pthread_mutex's one) but i wanted to know if you can by any chance have some (or all) fields of a struct filled at declaration.
For instance with the pthread_mu...