Posts Tagged ‘program’

Using the signal(…) routine (defined in the csignal or signal.h headers), you can define how various signals are handled by your program. The routine takes two arguments; the first is the signal you wish to handle, and the second is the handling routine itself. The handling routine can be specified as SIG_DFL (default handling), SIG_IGN […]

My first FORTRAN 77 program

Posted: 27th September 2011 by Tim in Fortran
Tags: , , , , , , , , , ,

With sophisticated programming languages such as C++ and Java, it’s surprising to learn that FORTRAN is still widely used in the real world. FORTRAN 77, although approaching 35 years old, forms the backbone of many large-scale systems, and requires maintenance every now and then. I also believe that knowing basic FORTRAN 77 provides a useful […]

Reading from a file in C

Posted: 31st October 2010 by Tim in C
Tags: , , , , , , , ,

Reading data from a file is fairly common. The stdio.h provides us with a function, getline, which allows us to read lines from a file without worrying about buffer overflows and other memory corruption issues that C is famous for. The following code opens a file named “myfile.txt” and prints out each line with the […]

Millisecond timer in C / C++

Posted: 18th October 2009 by Tim in C, C++
Tags: , , , , , , , ,

If you’re looking for a timer with fairly good accuracy in C or C++, you can use the functions in time.h and sys/time.h to build a millisecond timer. This is useful for things like evaluating the execution time of a program, roughly accurate to the nearest microsecond. double get_time_ms() { struct timeval t; gettimeofday(&t, NULL); […]