Hello,
I am compiling under linux (GCC 4.4.2) and windows VS C++ Express Edition 2008
I am currently compiling under windows XP Pro 32bit, and have added this to my source code.
#if defined( WIN32 )
/* Do windows stuff here */
#endif
However, the code in the if statement is disabled (grayed out). However if I do the following:
#if ...
Hi,
My current implementation of an Hash Table is using Linear Probing and now I want to move to Quadratic Probing (and later to chaining and maybe double hashing too). I've read a few articles, tutorials, wikipedia, etc... But I still don't know exactly what I should do.
Linear Probing, basically, has a step of 1 and that's easy to do...
I have just started C very recently and I have been asked to answer some coding exercises in which the following piece of code appears:
typedef enum {
false = 0,
true = 1
} Bool;
Could someone please provide a brief and clear explanation to that?
Thanks very much.
...
I got a problem today. It had a method and I need to find the problem in that function. The objective of the function is to append new line to the string that is passed. Following is the code
char* appendNewLine(char* str){
int len = strlen(str);
char buffer[1024];
strcpy(buffer, str);
buffer[len] = '\n';
return buff...
Hi,
This is one of the programming questions asked during written test from Microsoft. I am giving the question and the answer that I came up with. Thing is my answer although looks comprehensive (at least to me), I feel that the number of lines can be reduced. It was asked in C and I am a Java person but I managed to code it (my answer...
Hello,
I'm programming a C/C++ client/server sockets application. At this point, the client connects itselfs to the server every 50ms and sends a message.
Everything seems to works, but the data flow is not continuous: Suddenly, the server doesn't receives anything more, and then 5 messages at once... And sometimes everything works...
...
In a c programming exercise I am asked to convert an int to char without using the C library.
Any idea how to go about it?
edit: what I mean by int is the built in C/C++ type
Thanks.
...
AFAIK, extern keyword should be used for declaration and no value can be associated with the variable being declared with extern keyword. But supposing I write a statement like
extern int i = 10;
Should the compiler flag an error for the same? I have seen some compilers being tolerant and ignoring this? Why is this so? What does the '...
What I need to do is use the read function from unistd.h to read a file
line by line. I have this at the moment:
n = read(fd, str, size);
However, this reads to the end of the file, or up to size number of bytes.
Is there a way that I can make it read one line at a time, stopping at a newline?
The lines are all of variable length.
...
Hi,
(1). When using C++ template, is it correct that the compiler (e.g. g++) will not compile the template definition (which can only be in header file not source file) directly, but generate the code based on template definition for each of its instantiations and then compile the generated code for its instantiations?
(2). If I want ...
I want to measure message latency and throughput for both TCP and UDP using C sockets. I am writing a client.c and server.c (Question 1: Do I have to?) that run on different servers to accomplish this. I have to take several measurements using different packet sizes and multiple trials and plot my results.
For message latency:
Send a pa...
hello
My Question is regarding performance of Java versus compiled code, for example C++/fortran/assembly in high-performance numerical applications.
I know this is contentious topic, but I am looking for specific answers/examples. Also community wiki. I have asked similar questions before, but I think I put it broadly and did not get...
I have created a header file and a corresponding .c file full of functions I would like to use with a java program. I created a JNI header file using javah. I'm using gcc to compile my header file. How can I link my regular c object file with my JNI static library to get a static library that utilizes my C library? I'm using gcc to c...
A potential employer requires me to take an online aptitude test before my interview (in this case the test is for C, from Previsor). Where can I take the same (or similar) test so I have a rough idea on what I should brush up on?
I've taken a similar test for C++ previously, so I have some idea of what to expect. I've also been studyin...
I came across this: Writing a compiler using Turbo Pascal
I am curious if there are any tutorials or references explaining how to go about creating a simple C compiler. I mean, it is enough if it gets me to the level of making it understand arithmetic operations. I became really curious after reading this article by Ken Thompson. The id...
root@everton-laptop:/opt/tinyos-1.x/apps/Blink# make pc
compiling Blink to a pc binary
ncc -o build/pc/main.exe -g -O0 -board=micasb -pthread -target=pc -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -fnesc-nido-tosnodes=1000 -fnesc-cfile=build/pc/app.c Blink.nc -lm
In file included from /opt/tinyos-1.x/tos/platform/pc/packet_...
I am a linguist in charge of a C program, so please excuse me if the answer is obvious. I have the following code:
typedef struct array_s {
(...)
void **value;
} array_t;
typedef array_t *array_pt;
array_pt array_new (int size) {
(...)
array->value = (void **)malloc(size*sizeof(void *));
}
void* array_get (array_pt arr, int i)...
Is there a simple library to benchmark the time it takes to execute a portion of C code? What I want is something like:
int main(){
benchmarkBegin(0);
//Do work
double elapsedMS = benchmarkEnd(0);
benchmarkBegin(1)
//Do some more work
double elapsedMS2 = benchmarkEnd(1);
double speedup = benchmarkSpeedup(el...
Sorry for a very generic sounding question.
let's say
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SERVER_ADDRESS "123.456.789.012"
#define CLIENT_ADDRESS "123.456.789.013"
#define SERVER_TCP_PORT "1234"
#define CLIENT_...
I'm using C and pthread on a Linux machine, and I'm having trouble parallelizing a program.
I'm basically trying to take in a folder of data files, divide them into groups, each group handled by a thread, and run a function on each of the data file.
The way I'm doing this is I have a global char **filename variable, where filename[i] ...