c

Write this piece of Java in C?

I am not a C programmer. I have just started reading K&R's TCPL last week. I have written this 42 line code in Java. I tried converting it to C, but it is giving me a segmentation fault. Here is the Java version: http://codepaste.net/m8jz6m My failed attempt to port it to C: //Not working. #include <stdlib.h> #include <string.h>   voi...

Only disk writes but iotop shows reads as well

Hi, I'd like to understand the following issue: A process is doing write sys call only, in an infinite loop. When I bring up iotop I would expect to see non-zero write speed and zeroed read speed related to that process. But iotop tells read and write can be equal (depending on single write size). Have a look at the C code: #include <...

What does "Lower precision in wider context" warning actually mean?

I have the following code, for an embedded platform where an int is 16 bits and a long int is 32 bits: #define MULTIPLIER 0x1000 static void my_function(uint16_t i, void *p) { uint32_t start = MULTIPLIER * i; ... } My compiler gives me the warning: Warning 1 : lower precision in wider context: '*' for this line. What does...

How to get handles to all windows of another application

Hi, in my application i have timer, in TimerProc i want to get handles of all windows(main and child) of the another application that has focus. I have no idea how to do that because i don't understand functions like GetNextWindow or GetParent and Z-oder of windows and i can't find anywhere very detailed explanation of how this functions...

Asymptotically Fast Associative Array with Low Memory Requirements

Ok, tries have been around for a while. A typical implementation should give you O(m) lookup, insert and delete operations independently of the size n of the data set, where m is the message length. However, this same implementation takes up 256 words per input byte, in the worst case. Other data structures, notably hashing, give you ex...

Underscore function

I'm here watcing at some C source code and I've found this: fprintf(stderr, _("Try `%s --help' for more information.\n"), command); I already saw the underscore when I had a look at wxWidget, and I read it's used for internationalization. I found it really horrible (the least intutive name ever), but I tought it's just another weird w...

ifdef & solaris

Hi I want to undefine variable when compiling on SunOS. Therefore, i tried to put #ifdef SunOS #undef FOO #endif but it does not work. The problem is in #ifdef sunos ? Should i declarate it, or complier do it by itself ? regards S. ...

How to understand everything regarding a Simple Program creation?

I have referred quite a few books on C, C++, etc. in fact i have even read the Dragon book on Compilers. But my basic doubt remains, is there any link or book i can read which explains a simple C program creating from writing source code in a Editor to Compilation to Linking? Would appreciate an internet link is provided. ...

Implementing GetBSDProcessList from sysctl.h

Hello, Could someone give me some advice or a snippet of code that would show me the way of implementing the method in this listing . I would like to get some info about processes on a mac. I'm not so good with C, but am familiar with Objective C. Thanks! ...

How to generate Fibonacci faster

Hello! I am a CSE student and preparing myself for programming contest.Now I am working on Fibonacci series. I have a input file of size about some Kilo bytes containing positive integers. Input formate looks like 3 5 6 7 8 0 A zero means the end of file. Output should like 2 5 8 13 21 my code is #include<stdio.h> int fi...

How to know what function called another

Hi, I wanna know if there is any way to know where the function currently in execution was called, this is, in what file and line. I'm using C language, and I'm looking for something similar to _FUNCTION_, _LINE_ or _FILE_ macros. Best regards, Sérgio ...

Imitate/emulate a big-endian behavior in C?

I was wondering if it's possible to emulate a big-endian behavior, for testing purpose? via either windows or linux , mingw or gcc. Here's a sample of code which I would like the emulation to return big endian: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #if CHAR_BIT != 8 #error "Unsupported char si...

Accessing command line arguments in C

Hello, please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this: #include <stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi...

Python - Using os.popen() to parse Unix "ls" - Problems with Killing Child Process

Hi all. From my understanding, os.popen() opens a pipe within Python and initiates a new sub process. I have a problem when I run a for loop in conjunction with os.popen(). I can't seem to CTRL+C out of the loop. Here is my code: for FILE in os.popen("ls $MY_DIR/"): os.system("./processFile " + FILE) Whenever I try to CTRL+C, ...

error: ambiguous overload for 'operator/'

Hello, I am new to c, and the following is giving me some grief: int i,j,ll,k; double ddim,ddip,ddjm,ddjp,ddlm,ddlp; for(i=1; i<(mx-1); i++){ for(j=1; j<(my-1); j++){ for(ll=1; ll<(mz-1); ll++){ ddim=0.5*k ddip=0.5*k ddjm=0.5*k ddjp=0.5*k ddlm=0.5*k ddlp=0.5*k Wijl(i,j,ll) = ((1.0/h_x)*(ddip) \ ((1.0/h_x)*(ddim)) \ ...

Why is my multi-dimensional dynamic allocation in C not working?

Hi all, I have been trying to figure out the problem with my allocation and use of a multidimensional dynamically allocated array in C. I'd really appreciate any help. I've tried two approaches. The first: cdr = (double ***) malloc(NUM_REGIONS * sizeof(double **)); for(i=0; i<NUM_REGIONS; i++){ cdr[i] = (double **) malloc(numRating...

How commonly used are the xilinx chips?

I'm beginning to learn embedded with C (and maybe some C++) and someone from the office said they're willing to donate a free xilinx chip they've got sitting on their shelf. I was thinking more along the lines of an Arduino, especially that the Arduino tutorials and sample projects are abundant. Can someone confirm how xilinx chips co...

Which complements Python best: Java, C, or C++?

I am in the process of applying to a Computer Science program which requires students to have at least an intro-level exposure to either Java, C or C++. I have some experience with Python and I would prefer to continue working in Python before starting another language; however, the professor said that Python was too light, i.e. "it's j...

How does temporary storage work in C when a function returns?

I know C pretty well, however I'm confused of how temporary storage works. Like when a function returns, all the allocation happened inside that function is freed (from the stack or however the implementation decides to do this). For example: void f() { int a = 5; } // a's value doesn't exist anymore However we can use the retu...

Data types in C

A long double is known to use 80 bits. 2^80 = 1208925819614629174706176; Why, when declaring a variable such as: long double a = 1208925819614629174706175; // 2^80 - 1 I get a warning saying: Integer constant is too large for its type. ...