c

is there a function like getdelim is c++?

Hi, Is there a function in c++ that works like the getdelim function in c? I want to process a file using std::ifstream object, so I cannot use getdelim here. Any help would be much appreciated. Thanks. ...

export C #defines as shell variables

In my project, a number of paths to various directories, files and other components of the system are stored as #defines in a filenames.h, a file included by all that need them. It works well for all the various binaries generated by compilation, but the project also includes a few shell scripts that use the same paths. Currently this me...

Allocating memory for new element in linked list in C

Hi, I'm trying to create a linked list, I've got it working, but I'm still a little confused. I'm using the following struct: typedef struct _MList { int dx; int dy; struct _MList *next; } MList_t, *MList_p; I've tested that this structure makes sense, and I've got a function to print out a list: void mListPrint(MList_t *...

How to return a value from thread in C.

Hello, I'am new to C and would like to play with threads a bit. I would like to return some value from a thread using pthread_exit() My code is as follows: #include <pthread.h> #include <stdio.h> void *myThread() { int ret = 42; pthread_exit(&ret); } int main() { pthread_t tid; void *status; pthread_create(&tid, NULL...

(How) Can I reduce socket latency?

Hello, I have written an HTTP proxy that does some stuff that's not relevant here, but it is increasing the client's time-to-serve by a huge amount (600us without proxy vs 60000us with it). I think I have found where the bulk of that time is coming from - between my proxy finishing sending back to the client and the client finishing rece...

How to run .exe binary of a remote server on the remote server from a c++ application in windows platform

What are the ways to run .exe binary of a remote server on the remote server from a c++ application in windows platform?? ...

How do I get the selected text from the focused window using native Win32 API?

My app. will be running on the system try monitoring for a hotkey; when the user selects some text in any window and presses a hotkey, how do I obtain the selected text, when I get the WM_HOTKEY message? To capture the text on to the clipboard, I tried sending Ctrl + C using keybd_event() and SendInput() to the active window (GetActiveW...

Using named pipes in a single process

I am trying to use a named pipe for communication within a process. Here is the code #include <stdio.h> #include <fcntl.h> #include <signal.h> void sigint(int num) { int fd = open("np", O_WRONLY); write(fd, "y", 1); close(fd); } main() { char ch[1]; int fd; mkfifo("np", 0666); signal(SIGINT, sigint); ...

program that will compile in C but not in c++

this question was asked to my friend in an interview. "can you write any program that will compile in C but not in C++". is there any such program? ...

Can't find my syntax error, VC++ says there's one

I'm running into a bit of a problem here, I'm messing around with machine code and function pointers, and there's a bit of my code that VC++ simply refuses to compile. This compiles and runs exactly as expected: #include <stdlib.h> #include <stdio.h> int main() { char tarr[] = {0xb8, 222, 0, 0, 0, 0xc3}; int (*testfn)() = tar...

Is the RLE algorithm flawed?

I was looking at a recent Code Golf on the removal of duplicate characters in a string. i mulled it over and thought that the RLE algorithm would solve it, in fact, I did believe that would resolve removing duplicates, I wrote an implementation here in C, to see how far I could go with it char *rle(const char *src){ char *p=(char *...

In C, why is sizeof(char) 1, when 'a' is an int?

I tried printf("%d, %d\n", sizeof(char), sizeof('a')); and got 1, 4 as output. If size of a character is one, why does 'c' give me 4? I guess it's because it's an integer. So when I do char ch = 'c'; is there an implicit conversion happening, under the hood, from that 4 byte value to a 1 byte value when it's assigned to the char variab...

why we use any value in exit function in loop in c language

In C/C++ language loop statements we use exit(0), or exit(1) or other values. What is needed of that value, what is the role of that value in a loop when we exit the loop, and what is the meaning of 1 and 0 in exit()? ...

In C, main need not be a function?

This code compiles, but no surprises, it fails while linking (no main found): Listing 1: void main(); Link error: \mingw\lib\libmingw32.a(main.o):main.c:(.text+0x106) undefined reference to _WinMain@16' But, the code below compiles and links fine, with a warning: Listing 2: void (*main)(); warning: 'main' is usually a function ...

How to determine the total character length of the elements of an array of char pointers?

I got the following problem: I have an array of char pointers char *opts[] = { "-a", "--append", "-b" }; and a command name stored in char cmd[] = "ls"; Now I need to compute all possible combinations, which I've done using the GNU Scientific Library and execute the command with the compute combinations. The problem I have is ho...

How to set color to every widget in GTK

I am BE student.In my BE project i m using GTK.. I want C code for setting color of every widget in GTK . Plase help me out ...

Print whole string verbatim in gdb

I'm printing a string(char *) in gdb (gdb) p l l=0x9aa1f48 "up2 129104596496602200 19 0 0 3 0 eth1 XX :001CB",'0' <repeats 12 times>, "DC" Is there a setting to have p print the whole string and not fill inn the "repeats ... ". While at it - also extend the default printable length of a string, p seems to cut off if the string is quit...

Managing windows API differences between Windows XP and Vista/Server 2008

I am trying to create a single executable of a simple Win32 application that has to be able to run on both Windows XP and Windows Vista/2008. Due to some changes in the way Vista works some extra Win32 API calls have to be made to make the program function correctly as it did on XP. Currently I detect if the application is running on a...

static function faster?

Can a static function in C be potentially faster because the compiler's optimizer sees all the call sites and therefore optimizes the epilog and prolog of the called function? ...

how to store a very long integer value in c program for exam :- 98474737475747374739399

I have so store a very long value of type integer that can't be stored in a variable of long type. how can i store such a long integer value in a c programme. Please illustrate it through an example/ programme if possible. ...