Help with getting started for coding

Hi all.

I use openSUSE 12.1 x86_64, GNOME 3.2, and I want to get started at coding on C++ and Java on Linux. Previously I did on Windows, but I need a bit of help on Linux.

I’ve already installed gcc and gcc-c++ packages. I use Gedit as text editor. If I have an already written C or C++ program on Gedit, how can I compile and run the program? Can I also generate executable files?

Also, for Java, what are the packages needed for development work, and how can I compile, run and generate executable files?

Sorry for the questions, I’m still noob at coding on Linux…

I also heard about an environment, or kind of, named Eclipse, but I was first taught coding by using text editors and compiling…

Thank you.

http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html seems like a good
intro. If that doesn’t get you started, you might try googling
“compiling with gcc” and see what comes up.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

You have allready installed a few things you think you might need, but there are some “patterns” designed that will give you a few things you might not think of, but that you nevertheless will need.

YaST > Software > Software managemnet. Then in the View button ((top-left) choose Patterns. Then scroll down to developement and check things like Basic Developement and in your ccae C/C++ and Java Developement.

Am 01.07.2012 05:36, schrieb F style:
> Also, for Java, what are the packages needed for development work, and
> how can I compile, run and generate executable files?

This gives you the simplest imaginable example for java and howto
compile it to a class file from the command line
http://docs.oracle.com/javase/tutorial/getStarted/cupojava/unix.html

You need to have the package java-1_6_0-openjdk-devel installed (install
it with yast or zyppper).


PC: oS 12.1 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.4 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10

Thanks for your help very much. It’s been a while since the last time I learned C and C++, so I wanted to test one of my practice basic programs:

#include <stdio.h> 
#include <stdlib.h> 
#include <math.h>
#include <time.h>
#include <string.h>
 
#define PI 3.1416
#define SIZE 5
#define ROWS 5
#define COLUMNS 5
 
float hypotenuse(); 
int array(); 
int matrix(); 
void message();
 
int main() 
{ 
      message();
      int radius; 
      double area; 
      printf("
Greetings
"); 
      printf("WTH is this?
"); 
      printf("Circle area
"); 
      printf("Enter circle radius (integer): "); 
      scanf("%i", &radius);
      area = radius * radius * PI; 
      printf("Circle area: "); 
      printf("%lf
", area);
      printf("Hypotenuse
"); 
      hypotenuse(); 
      printf("Arrays
"); 
      array(); 
      printf("Matrix
"); 
      matrix(); 
      printf("Char exercises
"); 
      char text[80] = "Greetings"; 
      char name[100]; 
      char surname[100]; 
      printf("Enter your name: "); 
      scanf("%s", &name);
      char c = getchar(); 
      printf("Enter your surname: "); 
      gets(surname); 
      printf("¡ %s %s %s!
", text, name, surname); 
      system("PAUSE");
      return 0; 
} 
 
void mensaje(){ 
     printf("Hello world"); 
} 
 
float hypotenuse(){
     float side1, side2; 
     printf("Enter side 1: "); 
     scanf("%f", &side1); 
     printf("Enter side 2: "); 
     scanf("%f", &side2); 
     float hypotenuse = sqrt(pow(side1,2) + pow(side2,2)); 
     printf("Hypotenuse = %f", hypotenuse); 
} 
 
int array(){ 
     int array1] = {1, 2, 3};
     int array2[size=];
     for (int i = 0; i < SIZE; i++) { 
         printf("Enter value of element # %i: ", i); 
         scanf("%i", array2*); 
     } 
     printf("Displaying array 1:
"); 
     for (int i = 0; i < 3; i++) { 
         printf("array1%i]: %i
", i, array1*); 
     } 
     printf("Displaying array 2:
"); 
     for (int i = 0; i < SIZE; i++) { 
         printf("array2%i]: %i
", i, array2*); 
     } 
} 
 
int matrix(){ 
     int matrix[ROWS][COLUMNS]; 
     srand(time(0)); 
     for (int i = 0; i < ROWS; i++) { 
         for (int j = 0; i < COLUMNS; i++) { 
             matrix*[j] = (rand() % 100) + 1; 
         } 
     } 
     printf("Displaying matrix values:
"); 
     for (int i = 0; i < ROWS; i++) { 
         for (int j = 0; i < COLUMNS; i++) { 
             printf("%i	", matrix*[j]); 
         } 
         printf("
"); 
     } 
}

(I had to translate it, it wasn’t in English and I don’t trust online translators, in case there are naming mistakes…). I was sure I had this one working back then, but I ran it and when reaching the array function, I entered the first value of the array (position 0) and program returned “Segment violation”. Then I tried entering a letter instead of a number, just to see what happened. Result:

Enter value of element # 0: s
Enter value of element # 1: Enter value of element # 2: Enter value of element # 3: Enter value of element # 4: Displaying array 1:
array1[0]: 1
array1[1]: 2
array1[2]: 3
Displaying array 2:
array2[0]: 1630627808
array2[1]: 32713
array2[2]: 1627385639
array2[3]: 32713
array2[4]: 1630627808
Matrix
Displaying matrix values:
69    8    52    15    22    
Char exercises
Enter your name: Enter your surname: L
� Greetings s L!
sh: PAUSE: command not found

This time the program reached the end, but please check the details. Strange values on array2 (didn’t let me to introduce the values), didn’t let me enter the name and instead displayed the letter I entered in array2 as a name… And on top, PAUSE command not found.

Back in the course I remember we used Dev C++ on Windows, and now using g++ on Linux I’m getting this. Could it be compiler issues? Or do I need to deep check the coding (already doing it…)?

Thanks for your help.*****[/size]

Hi, this is a prime example of why not to use scanf. You should empty the keyboard buffer after each scanf (eg with getchar). HTH Lenwolf.

Am 04.07.2012 11:36, schrieb lenwolf:
>
> Hi, this is a prime example of why not to use scanf. You should empty
> the keyboard buffer after each scanf (eg with getchar). HTH Lenwolf.
>
In addition to that I want to add a comment about


system("PAUSE");

this is windows only. It calls a system command “pause” which exists on
windows and makes no sense at all here on linux when you run in a terminal.
Just remove that.


PC: oS 12.1 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.4 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10