< Browse > Home /

How to add Open in Terminal support To Nautilus in Ubuntu

March 9th, 2010 | No Comments | Posted in Linux, Tips, Ubuntu by Diego | - [Full Entry]

Wouldn’t it be great to open up Nautlius (equivalent to Windows-Explorer in Ubuntu) and be able to open up your terminal in that specific folder by simply right clicking and choosing an Open in Terminal option? Unfortunately this option isn’t set by default. Luckily there are two ways to install this option.

  1. Installing through the terminal (easiest)
  2. Installing through the Synaptic Package Manager

Read more »

Command Line Arguments

August 2nd, 2008 | No Comments | Posted in C++ by Diego | - [Full Entry]

Command Line Arguments allow the user to run the program thruogh the terminal as well as pass in arguments into your program in one line. Most common use of command line arguments, are to pass in “strings” that represent file names from which you are going to read data from.

Format of Command Line Arguments

This is how you would write a simple program without command line arguments.

#include  <iostream>
using namespace std;  

double square(int number) {      
     return number*number; }  

int main() {      
     int number;      
     cin >> number;      
     cout << square(number) << endl;    
     return 0;
}

To run this program you’d do the following in the terminal. ($ denotes your input)

$./a.out
$10        //Your input
 100      //The output

Using Command Line Arguments

This is how you would use command line arguments.

#include <iostream>
 using namespace std;  

double square(int number) {      
     return number*number; }  

int main(int argc, char* argv[]) {    
      int number = atoi(argv[1]);      //Convert our c-string to int using the atoi function
      cout << square(number) << endl;      
      return 0;
}

To run this, you’d simply do the following in the terminal.

$./a.out 10 //One line in the terminal
100 //Output

How does command line arguments work?

int main(int argc, char* argv[])

The int argc parameter denotes the number of arguments passed in.
The char* argv[] parameter denotes a char pointer to a c-string.

So, typing the following:

$./a.out 10 45

Would produce the following:

In other words, the arguments are passed in as c-strings reason for why we converted our c-string to an int using the atoi function.

Things to do with Command Line Arguments

You may pass in any type of arguments. Try the following challenges to learn more.
Challenge 1: Create a program using command line arguments where you pass in your name, and two numbers, adds the numbers together and displays them both in the terminal.
Challenge 2: Create a program that accepts one int and returns the square of the number as shown above. The difference is that you need to error check your program. In other words, if they don’t pass in an int value or more than one int value, you should terminate the program. Hint: Use argc, and if statements.

Need more help? Go ask in the forums where our committed community will surely answer all your questions!

Basic Linux Terminal Commands

June 5th, 2008 | No Comments | Posted in Linux by Diego | - [Full Entry]

If you are new to Linux and it’s terminal, you might be wondering how to move around? I’ll show you how with some basic terminal commands.

Below I’ll list a few examples with comments denoted by // Read more »

How to write and compile C++ program in Linux

May 29th, 2008 | 25 Comments | Posted in C++ by Diego | - [Full Entry]

Here is a step by step detailed guide on showing you how to write and compile a C++ program in Linux. For demonstration purposes, I’ll show you how to write and compile Hello World!

Difficult: Relatively Easy

How to write and compile Hello World in C++

1. First, let’s locate and open up our handy terminal.

terminal c++ hello world
Read more »