Pages

Saturday, March 24, 2012

getch(), getche() & clrscr() in gcc

Sometimes, we need to use "conio.h" in Linux (gcc). Functions like getch(), getche() and clrscr() are present in the header file "conio.h". getch() prompts the user to press a character and that character is not printed on screen. getche() prompts the user to press a character and that character is printed on screen. clrscr() clears the console screen.
Given below is the code you need to save under the name conio.h to make the functions work.
       
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

/* reads from keypress, doesn't echo */
int getch(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON | ECHO );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

/* reads from keypress, echoes */
int getche(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

/* Clears screen */
void clrscr(void)
{
 system("clear");
}       
 

Just include the above header files and you can use the these functions.

#Source: Internet

Friday, March 9, 2012

Install Dropbox in Ubuntu

Dropbox is a Web-based file hosting service operated by Dropbox, Inc. that uses cloud storage to enable users to store and share files and folders with others across the Internet using file synchronization. Dropbox provides 2 GB of free online storage. Users who refer Dropbox to others can gain up to 8 GB of additional free storage.

For installing Dropbox, download it from here:
     Ubuntu (.deb)       32-bit            64-bit 
For installing the .deb file, simply double-click on it and then select Install Package.

Alternatively, you can also install a .deb file by opening terminal and typing:
$ sudo dpkg -i package_file.deb
Install Dropbox Via Command-Line
To install, run the following command in your Linux terminal.
32-bit
$ cd ~ && wget -O - http://www.dropbox.com/download?plat=lnx.x86 | tar xzf -
64-bit
$  cd ~ && wget -O - http://www.dropbox.com/download?plat=lnx.x86_64 | tar xzf -
 Next, run the Dropbox daemon from the newly created .dropbox-dist folder.
$  ~/.dropbox-dist/dropboxd
If you're running Dropbox on your server for the first time, you'll be asked to copy and paste a link in a working browser to create a new account or add your server to an existing account. Once you do, your Dropbox folder will be created in your home directory.
Source:  Dropbox