c

fast retrieval of (void *) memory block

Hi, I have a system that returns a void* to a memory block. This memory block stores contiguous data records of different types(int,char,double etc.) and gives the number of bytes of each field in each record.I essentially look up the type of the record and get the value of the record. To retrieve all the records, I do switch(type) { ...

How to allocate more memory to your program( GCC)

Hi, I want to allocate more memory to program.l What is the gcc flag that allows you to do so? FYI what I am trying to do is create a very large matrix( really large) which is gonna go through compression algorithms later. So there is no way I can avoid creating such a large matrix to store data. ...

using malloc for the life of the program

Hello, gcc 4.4.4 c89 I have always thought of using malloc for the life of the project for being the scope. But I am just wondering if my idea is the best practice. For example, I initalize an instance of the struct in main. And create 2 functions for creating and destroying. I am just wondering if this is the right thing to do. I h...

initialize a multidimensional C array of variable size to zero

I want to initialize a two-dimensional array of variable size to zero. I know it can be done for a fixed-sized array: int myarray[10][10] = {0}; but it is not working if I do this: int i = 10; int j = 10; int myarray[i][j] = {0}; Is there a one-line way of doing this or do I have to loop over each member of the array? Thanks ...

How do I convert this C code into Python?

I am trying to convert this C code I have into a python script so it's readily accessible by more people, but I am having problems understanding this one snippet. int i, t; for (i = 0; i < N; i++) { t = (int)(T*drand48()); z[i] = t; Nwt[w[i]][t]++; Ndt[d[i]][t]++; Nt[t]++; } N is a value (sum of one column from an array...

Creating window using glut, but program is inconsistent.

I'm just trying to make a program that displays a window with a box in it, but when I run the program I only get the window display maybe once out of 5 runs. Every time I execute the command line gives appropriate responses and i see the window's title on the gnome panel at the bottom of the screen, but the window itself is invisible mos...

sse inline assembly with g++

I'm trying out g++ inline assembly and sse and wrote a first program. It segfaults - why? #include <stdio.h> float s[128*4] __attribute__((aligned(16))); #define r0 3 #define r1 17 #define r2 110 #define rs0 "3" #define rs1 "17" #define rs2 "110" int main () { s[r0*4+0] = 2.0; s[r0*4+1] = 3.0; s[r0*4+2] = 4.0; s[r0*4+3] = 5.0; ...

square of a number being defined using #define

Hi, I was just going through certain code's which are frequently asked in Interview's. I came up with certain doubts, if anyone can help me regarding this? I am totally confused on this now, #include<stdio.h> #include<conio.h> #define square(x) x*x main() { int i,j; i=4/square(4); j=64/square(4); printf("\n %d...

cannot free memory

Hello, gcc 4.4.4 c89 I have the following function but I cannot free the memory. The message I get in Valgrind is suspecting the getline function. However, I am free the file pointer at the end of the function. So it cannot be that. I have a global array of pointers to char 'candidate_names'. However, I haven't allocated any memory f...

Sockets and threads using C.

I am new to both sockets and threads. I have this code: listen(socket_fd, 20); /* Looooop */ while (1) { newsocket_fd = accept(socket_fd, (struct sockaddr *) &client_addr, &client_len); if (newsocket_fd < 0) { error("ERROR on accept"); } pthread_t thread; ...

Getting current Windows system input language and notifications when the language changes.

I am writing on screen keyboard application. The keyboard is running in separate process and the application window is topmost and does not get focus. When I switch between applications, the language is changed. How can I get the current selected language on toolbar and how can I be notified when it is changed? InputLanguageManager and ...

Dijkstra on adjacency matrix in C

Hi all, I need some help with Dijkstra's algorithm in C. I've generated my adjacency matrix, that looks something like: int mat[NB][NB] = {{0, 171, MAX, 132, [...]}, {171, 0, 30, 39, [...]}, , [...]}; I've found this implementation: http://www.answers.com/topic/dijkstra-s-algorithm-1 but the path is an 1-dimensional array and my ma...

error: expected ')' before '*' token

I have this include file (memory .h) #ifndef MEMORY_H #define MEMORY_H #ifdef __cplusplus extern "C" { #endif typedef struct mmemory { int* cells; int* current_cell; int cells_number; } memory; void memory_init(memory* mymemory, int size); void step_left(memory* mymemory, int steps); void ...

C - How can I save structs to a malloc'd section of memory?

My question's pretty basic, but it's been a while. I'm reading in a text file and saving numbers in the text to a struct 'Record'. After I read text to my Record buffer, I want to place it in an area of memory. typedef struct { int line_status[64]; float line_data[64], relativetime; unsigned long blkhdr_ticks; } Record; Record *sto...

Appending to a global file handle, is it bad?

Lets say there are multiple functions throughout my program that need to append data to a certain file. I open the file at the beginning of the program with a global file handle so I can append to it wherever I need to. (Note that I know I could pass the file handle as an argument to the functions but that is not the purpose of this ques...

UNIX C BSD Sockets TCP_KEEPALIVE how to check if socket is marked as broken

I have been trying to implement the TCP_KEEPALIVE parameter for a C server socket and I can't seem to figure out how to check if the socket is marked as broken. I followed this tutorial for configuring the socket to do the keep alive but it says that "If no ACK response is received for nine consecutive times, the connection is marked as...

Is there a good reason to write my own daemonize function instead of using daemon(3)?

There are a lot of example implementations of daemons on the net. Most that I saw do not use the daemon(3) function to run the program in the background. Is that just a matter of taste, ignorance, or is there a good reason to write my own daemonize function? Is there a specific disadvantage in using daemon(3)? Is it insecure? ...

Machine Learning Library?

Which libraries do you use for machine learning for C/C++, Python, Java? ...

UTF-8 -> ASCII in C language

Hi guys. I have a simple question that I can't find anywhere over the internet, how can I convert UTF-8 to ASCII (mostly accented characters to the same character without accent) in C using only the standard lib? I found solutions to most of the languages out there, but not for C particularly. Thanks! EDIT: Some of the kind guys that c...

Why do I not see the "Application Error" dialog box?

I was interested in learning more about mixing runtimes between exes and dlls. On a WinXP machine, I created a dll build against the release runtime (/MD) and an exe that calls a function in the dll that is built debug (/MDd). The function in the dll allocates memory to the heap and the exe deletes it. I expected this to crash, howeve...