c

How can I create an fscanf format string to accept white space and comma (,) tokenization

I've got some analysis code (myprog) that sucks in data using the following: if(5 == fscanf(in, "%s%lf%f%f%f", tag, & sec, & tgt, & s1, & s2)) which works just fine. But in the situation where I've got data files that are separated by commas, I'm currently doing something like: sed 's/,/ /g' data | myprog Can I modify the format...

Convert UTF-16 to UTF-8 under Windows and Linux, in C

I was wondering if there is a recommended 'cross' Windows and Linux method for the purpose of converting strings from UTF-16LE to UTF-8? or one should use different methods for each environment? I've managed to google few references to 'iconv' , but for somreason I can't find samples of basic conversions, such as - converting a wchar_t ...

Different standard streams per POSIX thread

Is there any possibility to achieve different redirections for standard output like printf(3) for different POSIX thread? What about standard input? I have lot of code based on standard input/output and I only can separate this code into different POSIX thread, not process. Linux operation system, C standard library. I know I can refact...

conditional operator in C question

I just have a quick question about the conditional operator. Still a budding programmer here. I am given x = 1, y = 2, and z = 3. I want to know, why after this statement: y += x-- ? z++ : --z; That y is 5. The values after the statement are x = 0, y = 5, and z = 4. I know the way the conditional operator works is that it is formatte...

C/C++ Union Question

union { int i; bool b; } x; x.i = 20000; x.b = true; cout << x.i; It prints out 19969. Why does it not print out 20000? ...

Including C header file with lots of global variables

I have an include file with 100+ global variables. It's being used in a library, but some programs that I'm linking the lib to also need to access the globals. The way it was built: // In one library .c file #define Extern // In the programs that use the globals #define Extern extern // In the .h file Extern int a,b,c; I had a hard...

SWT-like GUI toolkit for C

Hello, do you know any cross-platform gui toolkit like swt for C (using default widgets in each operating system = right pics on eclipse.org/swt) ? There is an implementation of swt for D language called DWT but I need it for C or C++. Thanks. ...

C++ assignment - stylish or performance?

Having been writing Java code for many years, I was amazed when I saw this C++ statement: int a,b; int c = (a=1, b=a+2, b*3); My question is: Is this a choice of coding style, or does it have a real benefit? (I am looking for a practicle use case) I think the compiler will see it the same as the following: int a=1, b=a+2; int c = b*...

whats wrong with strcpy()

What is wrong with strcpy() in this code? void process_filedata(char *filename) { void* content; const char * buffer; char * temp; char * row; char * col; int lsize,buflen,tmp,num_scan; //num_scan - number of characters scanned int m=0,p=0,d=0,j=0; //m - machine, p - phase, d- delimiter, j - job FILE *file_pointer = fop...

Shrinking or partially truncating a file in DOS/FAT

I've been tasked with writing a data collection program for a Unitech HT630, which runs a proprietary DOS operating system that can run executables compiled for 16-bit MS DOS with some restrictions. I'm using the Digital Mars C/C++ compiler, which is working well thus far. One of the application requirements is that the data file must...

Sending 2 dim array using scatter

I am a beginner in MPI, and i am using C Language, and Simulator for Processors (MPICH2), i wrote the following code to send a 2D array to make 2 processors take a line from it but it produces error when running MPICH2, the code is: #include <stdio.h> #include <stdlib.h> #include "mpi.h" int main(int argc, char *argv[]) { int r...

Point to point linear gradient?

I want to make an application that can generate point to point gradient (like Photoshop does). I'm familiar with how to generate an up to down gradient but not point to point. How is this conceptually done. Thanks ...

Remove GtkButton's image padding (inner-border)?

In C/GTK, is there a way to remove the inner-border for a GtkButton that has an image using gtk_button_set_image? gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); sort of did the job but a mouseover showed that it merely hides it. I would prefer to do this without using an RC style, but if there's no other way, an example ...

How does Photoshop (Or drawing programs) blit?

I'm getting ready to make a drawing application in Windows. I'm just wondering, do drawing programs have a memory bitmap which they lock, then set each pixel, then blit? I don't understand how Photoshop can move entire layers without lag or flicker without using hardware acceleration. Also in a program like Expression Design, I could hav...

FIFOs implementation

Consider the following code: writer.c mkfifo("/tmp/myfifo", 0660); int fd = open("/tmp/myfifo", O_WRONLY); char *foo, *bar; ... write(fd, foo, strlen(foo)*sizeof(char)); write(fd, bar, strlen(bar)*sizeof(char)); reader.c int fd = open("/tmp/myfifo", O_RDONLY); char buf[100]; read(fd, buf, ??); My question is: Since it's not ...

How does this iterative Tower of Hanoi work? C

Possible Duplicate: How does this work? Weird Towers of Hanoi Solution Hello, while surfing google, i found this interesting solution to Tower Of Hanoi which doesn't even use stack. Can anybody explain me in brief, what is it actually doing? And this solution really acceptable? #include <stdio.h> #include <stdlib.h> int main...

How do I practice C programming at home

I've took C programming class while back ago. Since I'm done with the class and don't have any access to the school lab anymore, can anybody give me suggestion how do I practice my c at home. Thanks ...

Execute another program in multi-threaded program

Hi, Just wondering how if it's possible to execute another program in a thread and send information to/get information from it. Essentially the same concept as with a child process and using pipes to communicate - however I don't want to use fork. I can't seem to find whether it's possible to do this, any help would be appreciated. Th...

[Glade] button problem

Hi, i'm using glade to designa a interface for my program written in C but i have some problem with the buttons. Can someone explain me how to set in glade an action for a button? i mean, i wrote a function in my code but i don't know how to associate it to the graphic... i set i the Signal box the GtkButton activate and i chose "on_b...

How to print a dictionary in python c api function

PyObject* dict = PyDict_New(); PyDict_SetItem(dict, key, value); PyDict_GetItem(dict, key); Bus error if i use getitem function otherwise not. So Want to confirm that the dictionary has the same values which i have set. Other than using PyDict_GetItem function, Is there any other method to print the values of the dictionary? ...