c

C automatically assign port

Hi, I just wanted to know how to use C to automatically assign a free port (and see what was used) if a specific port number is not provided. For example, i'm using this: struct sockaddr_in address; address->sin_family = AF_INET; address->sin_addr.s_addr = INADDR_ANY; address->sin_port = htons( port ); But how can I replace the sin_p...

When assert() fails, what is the program exit code?

When an assert() call fails, what is the exit code used, and where is it documented? ...

What is mean by Million cycles per second(MCPS)

hi , I have seen some performance figures are represented by MCPS unit, especially in some dsp codec performance. Can anybody clarify me this? /kanu__ ...

Does control return after "execvp()" ?

if(pid == 0) { execvp(cmd, args); // printf("hello"); // apparently, putting this or not does not work. _exit(-1); } else { // parent process work } "execvp()" replaces the current program with the to-be-execed program (of course in the same process context). So, putting, say, any printf() calls after execvp() ...

C CLI game concept

So I just wanted to get some opinions on the overall structure of a game I have to build for a programming class. Essentially - I'm building two programs - a client and a server for a battleships game. I've already written the actual program which plays the battleships game. The program I've written is where a map and rules file is read...

Equivalent of open_memstream for MSVC

Hi, I am using *open_memstream* in a library of mine, but I would like to port this library to MSVC. It seems there are no equivalent function available, but is there something similar enough? What *open_memstream* does is it takes a char** destination and size and returns a FILE* which you many write to, the data is stored in a dynamic...

UTC timestamp in milisecond using c++ under windows

How to get the UTC time in milliseconds under windows platform. I am using Standard library which give me UTC time in seconds, I want to get time in miliseconds, kindly give me the reference of any other library which give me the accurate UTC time in miliseconds. ...

Valgrind 'noise', what does it mean?

When I used valgrind to help debug an app I was working on I notice a huge about of noise which seems to be complaining about standard libraries. As a test I did this; echo 'int main() {return 0;}' | gcc -x c -o test - Then I did this; valgrind ./test ==1096== Use of uninitialised value of size 8 ==1096== at 0x400A202: _dl_new_o...

How do I add a number in a sorted linklist?

I'm trying to make a function in C to add numbers to an ordered linked list, but I've got the feeling it can be done in a lot less rows. Is there an example? This example code does not work: #include <stdio.h> #include <stdlib.h> struct listNode { int number; struct listNode *nextPtr; }; typedef struct listNode LISTNODE; type...

copy string one place to another

copy string between comma input (aaa),(ddD),(sss),(ppp) p=malloc(sizeof(char)*200); gets(p); i want hold input p[0]="(aaa)" p[1]="(ddD)" p[2]="(sss)" p[3]="(ppp)" ...

gethostbyname in C

I don't know how to write applications in C, but I need a tiny program that does: lh = gethostbyname("localhost"); output = lh->h_name; output variable is to be printed. The above code is used in PHP MongoDB database driver to get the hostname of the computer (hostname is part of an input to generate an unique ID). I'm skeptical that...

Does waitpid yield valid status information for a child process that has already exited?

If I fork a child process, and the child process exits before the parent calls waitpid, then is the exit status information that is set by waitpid still valid? If so, when does it become not valid; i.e., how do I ensure that I can call waitpid on the child pid and continue to get valid exit status information after an arbitrary amount o...

Why are python extensions shared libraries? Is it possible to make a static-linked library?

I'm an extension noob. What I want to do is create an extension that doesn't require other libraries to be installed. Is this impossible because the extension has to link against a specific version of libpython at runtime? ...

Create a function pointer which takes a function pointer as an argument.

I'm trying to create a function pointer that takes a function pointer as an argument, but am not sure how to go about it... I was advised to try typedef-ing one of my function pointers, but get the same error. Could someone help me with the correct syntax? int 186 main(int argc, char **argv) 187 { 188 int i; 194 typ...

How do I get the index of the current Object in an NSEnumerator iteration?

Question: How do I get the index of the current Object in an NSEnumerator iteration? (I don't want to keep track of things using an integer counter or use a for loop due to speed reasons. I did it before I just cannot remember how I did it...) ...

Order of operations in C. ++ vs |=, which occurs first?

I have the following code that I'm reading through: if( (i%2) == 0 ){ *d = ((b & 0x0F) << 4); } else{ *d++ |= (b & 0x0F); }; I'm looking specifically at the else statement and wondering in what order this occurs? I don't have a regular C compiler, so I can't test this. When we are performing *d++ |= (b & 0x0F);, what orde...

Reading file into array

Hello, I have these a file in a c program which consist of a string and 4 doubles and 2 integer in one line and there is a total of 28 lines, i want to read this file and load the data into an array. can someone help me solve this. ...

pow doesn't accept the second parameter to be a variable on gcc

pow doesn't accept the second parameter to be a variable on gcc The following code works fine on VC++10 // file test.cc #include "stdafx.h" #include <stdio.h> #include <math.h> int main(void) { double x = 10; int y = 20; printf("%f\n", pow(x, y)); return 0; } But the following code doesn't not work on gcc: // tes...

"Implicit declaration" warning

For this code: int i=0; char **mainp; for(i=0;i<2;++i) { mainp[i]=malloc(sizeof(char)*200); if(!scanf("%[^#],#",mainp[i])) break; if(i<2) scanf("%[^#],#",mainp[i]); } GCC emits the warnings: warning: implicit declaration of function ‘scanf’ warning: incompatible implicit declaration of built-in function ‘sca...

Using netlink to obtain arp entries only returns stale entries

I'm currently trying to retrieve reachable neighbors from the arp table in a user space program written in c. I've looked through the source code to the "ip neigh" command (ipneigh.c) and it appears that I should use the flag NUD_REACHABLE to get the reachable nodes. However, when I look at the data returned from the kernel, I only hav...