Main Shell Script

Posted by Bl4ckB0y On 18.06 0 comments

ada sebuah persoalann sebagai berikut sebuah :
buatlah sebuah shell script yang dapat melakukan hal berikut :
input sebuah file txt
aku makan nasi
aku minum air
aku makan daging

program akan memotong tiap baris dari file dengan memotong beberapa karakter dari karakter ke m sampai ke n lalu hasilnya digabung dibagain bawah menjadi satu kalimat yang dipisah oleh spasi
misal input 6 sampai 8
hasilnya :
aku an nasi
aku um air
aku an daging
mak min mak
=================================================================================================

echo -n "Masukan Awal : "
read awal
echo -n "Masukan Akhir : "
read akhir
if [ $awal -gt $akhir ];
then
echo "Astagfirrullah !!!!"
exit 0
fi;
echo -n "Masukan Path File : "
read fill
baru=""
count=$(cut -c $awal-$akhir $fill | wc -l)
counter=1
while [ $counter -le $count ];
do
dua=$(cut -c $awal-$akhir $fill | head -$counter | tail -1 )
if [ $counter -eq 1 ];
then
hurufsatu=$(echo $dua | cut -c 1 | tr [[:lower:]] [[:upper:]])
dua=$(echo $dua | cut -c 2-)
dua=$hurufsatu$dua
fi;
baru="$baru $dua"
let counter=$counter+1
done

counter=1
let awal=$awal-1
let akhir=$akhir+1
while [ $counter -le $count ];
do
satu=$(cut -c -$awal $fill | head -$counter | tail -1)
dua=$(cut -c $akhir- $fill | head -$counter | tail -1 )
fbaru="$satu$dua"
if [ $counter -eq 1 ];
then echo $fbaru > metal2
else echo $fbaru >> metal2
fi;
let counter=$counter+1
done
echo $baru>>metal2

========================================================================================
compile dengan menggunakan chmod+777 dan jalankan

Upload JavaScript di Friendster

Posted by Bl4ckB0y On 04.58 1 comments

memasukan file berekstensi .js memang kadang berbahaya, namun apa salahnya kalau dicoba, berikut ini tahap-tahap buat memasukan file Javascript di Friendster.

1 . kita harus punya dulu file Javascript yang akan dimasukan. bisa membuat sendiri atau mencari di internet, kalau mau cari di Internet situs http://www.dynamicdrive.com/ cukup kompatible dengan Friendster
2. copy file script javascript yang tersedia di kotak. dan simpan dengan nama file .js
3. untuk mengupload file kunjugi http://www.fileave.com/ disini kita harus mendaftar dulu, atau bisa juga ditempat lain.
4. setelah itu masuk ke friendster teman-teman dan buka bagian edit profile..
masukan code ini :
(script languange="javascript" src="")(/script)

Contoh :
(script languange="javascript" src="http://chya_only_one.fileave.com/huda/coba.js")(/script)
ganti tanda () sama <>
begitulah dengan demikian file javascript sudah terupload, file ini bisa dibuat untuk memasukan virus, trijan atau apapun, kadang-kadang programmer jahat memasukanya untuk kepeluan keuntungan.
kalau teman-teman mau tahu gimana caranya buat javascript berbahaya, silakan aja di googling...
Insya Allah kapan-kapan tak kasih tau....

Ackerman

Posted by Bl4ckB0y On 04.47 1 comments

Ackerman merupakan sebuah program yang mengimplementasikan fungsi rekursif.....
yang mana ia akan memiliki 3 fungsi .......

/*
This program use to implement Ackerman function
With : a(m,n)------>return(a((m-1),a(m,n-1)))
a(0,n)------>return(n+1)
a(n,0)------>return(a(m-1,1))
Author : huda
e-mail : huda890@gmail.com
*/
/*iporting Input and Output Standart from java*/
import java.io.*;
/*declaration of ackerman class*/
class ackerman
{
/*declaration of main methode*/
public static void main(String args[]) throws IOException
{
/*build object of ackerman class*/
ackerman fungsi=new ackerman();
/*make object for input from console*/
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
int m,n;
String temporary;
System.out.println("Ackerman");
System.out.println("a(m,n)------>a((m-1),a(m,n-1))");
System.out.println("a(0,n)------>n+1");
System.out.println("a(n,0)------>a(m-1,1)");
System.out.print("insert value of M:");
/*read string from console*/
temporary=input.readLine();
/*convert string to integer*/
m=Integer.parseInt(temporary);
System.out.print("insert value of N:");
/*read input from console */
temporary=input.readLine();
/*convert from string to integer*/
n=Integer.parseInt(temporary);
/*call ackerman function*/
int result=fungsi.ackerman(m,n);
/*print to console the result*/
System.out.println(result);
}
/*ackerman methode */
int ackerman(int m, int n)
{
int result;
if(m==0 && n!=0)
{return(n+1);}
else
if (n==0 && m!=0)
{
result=ackerman(m-1,1);
/*return the result */
return(resultl);
}
else
if (m!=0 && n!=0)
{
result=ackerman(m,n-1); /*found the result of first function */
/*the result of the first function used to found the second result */
result=ackerman(m-1,result); /*found the final result*/
/*return the result*/
return(hasil);
}
else /*result 1 if n=0 and m=0*/
return(1);
}
}

GCD = FPB

Posted by Bl4ckB0y On 04.44 0 comments

GCD atau FPB adalah faktor persekutuan terbesar dari dua angka atau lebih. berikut ini source code untuk mencari sebuah FPB dari dua buah angka.....

/*
This class implement of GCD
We recommended you to using Jcreator pro v3.0
Author : huda
e-mail : huda890@gmail.com
*/
import java.io.*;
class gcd
{
public static void main(String args[])throws IOException
{
String temporary;
/*first number*/
int first_number;
/*second number*/
int second_number;
/*build object of gcd class*/
gcd number=new gcd();
/*build for input from konsole*/
BufferedReader input = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("GCD");
System.out.print("insert first number : ");
/*read string from console*/
temporary=input.readLine();
/*convert from temporary to integer and save to first_number*/
first_number=Integer.parseInt(temporary);
System.out.print("insert second number : ");
/*read string from console*/
temporary=input.readLine();
/*convert from temporary to integer and save to first_number*/
second_number=Integer.parseInt(temporary);
/*choose the proses*/
if(first_number>second_number)
number.proses(second_number,first_number);
/*if second number more less than first number*/
else
number.proses(first_number,second_number);
/*if second number more big than first number*/
}
/*the methode for found the gcd*/
int proses(int first,int second)
{
/*pivot is the temporary variable */
int pivot;
if(first!=0)
{
pivot=second;
second=first;
first=pivot%first;
/*recurtion function*/
return(proses(first,second));
}
/*print the gcd to console*/
System.out.println("GCD : "+second);
return(0);
}
}

Stack

Posted by Bl4ckB0y On 04.39 0 comments

Stack merupakan sebuah Struktur data yang dapat dibayangkan sebagai sebuah tumpukan (stack = tumpukan). contoh stack dalam kehidupan sehari-hari adalah sebuah tumpukan piring, dimana setiap kali piring terakhir yang kita tumpuk akan diambil terlebih dahulu. sifat stack adalah LIFO (last In forst out) --> artinya setiap data yang masuk terakhir kali akan keluar pertama kali....
berikut ini adalah source code implementasi dari sebuah stack....

/*
This Program Implemet about stack
Author : huda
e-mail : huda890@gmail.com
*/
import java.io.*;
class stack
{
static int MAXIMUMSTACK=10;
public static void main(String args[])throws IOException
{
stack s=new stack(); //build stack class
char temporary_character; //as temporary variabel to save char
String temporary_string; //temporary variabel for casting
int Choose; //this for choose
boolean flag=true; //flag for looping
int top=-1; //pointer of stack
char stack[]=new char[MAXIMUMSTACK]; //build stack object
int long_character=0; //show length of stack
/*make the buffer for input from console*/
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
/*main program*/
System.out.println("Stack");
System.out.print("insert String : ");
/*get char from console one by one */
while((temporary_character=(char)in.read())!='\n')
{
top++;
stack[top]=temporary_character;
}
top--; //character '\n' not use, so it must be pop
/*to show what user want*/
do
{
System.out.println("1.Pop 2.push 3.Print 4.exit");
System.out.print(“Inser your Choose:”);
/*because switch just use for primitif tipe, the string must be convert ot integer*/
temporary_string=in.readLine();
Choose=Integer.parseInt(temporary_string);
/*choosing*/
switch(Choose)
{
case 1: int y=s.pop(stack,top);top=y;break;
/*int y for save the value from return of pop*/
case 2: int x=s.push(stack,top);top=x;break;
/*integer x for save the return from push*/
case 3: s.Print(stack,top);break;
/*for print all data in the stack*/
case 4: flag=false;break;
/*Close porgram */
default : System.out.println("Wrong");
}
}while (flag);
}
/*for check Full stack*/
boolean full(int top)
{
if(top==MAXIMUMSTACK-1) //check stack full or not
return(true); //true if full
return (false); //otherwise false
}
/*for check the stack empty or not */
boolean empty(int top)
{
if(0>top) //check empty or not
return(true); //true if empty
return(false); //otherwise false
}
/*this function to push character*/
int push(char stack[],int top) throws IOException
{
if(!full(top)) //check stack full or not before pushing
{
char character;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Insert A Char : ");
character=(char) br.read(); //get char from console
stack[++top]=character;
/*if stack not full push wil progress*/
return(top);
/*return for x variabel*/
}
else
System.out.println("\nFull");
return(top);
/*return variabel to X*/
}
/*this methode to pop a character*/
int pop(char stack[], int top)
{
if ( empty(top)) //chaeck stack empty or not
{
System.out.println("Empty");
return(top); //return top for y variabel
}
else
{
System.out.println("Character : "+ stack[top]+" pop Succesfull");
return(--top); //return top for y variabel
}
}
/*print stack to console*/
void Print(char stack[], int top)
{
System.out.print("Stack is : ");
/*print all element to console from behind to top, (without pop proses) */
for (int i=0;top=>i;i++)
System.out.print(stack[i]);
System.out.println();
}
}

LinkedList

Posted by Bl4ckB0y On 04.37 0 comments

LinkedList merupakan sebuah struktur data yang mirip dengan Array akan tetapi Linkedlist memiliki perbedaan. Array berupa sebuah larik yang statis, yang mana jika kita memesan 10 lokasi memori kita akan diberi 10 lokasi memori, namun pada kenyataanya kadang-kadang kita membutuhkan lebih dari 10 lokasi memori, sehingga kita harus mengubah source code untuk menambah jumlah memori pada pesanan array source code kita...berbeda dengan linkedlist, walaupun tidak berurutan, linkedlist memilki kelebihan sifatnya yang dinamis membuat kita bebas dalam mengalokasikan memori, sebagai contoh saat kita bisa memesan 10 memori atau 1 memori saja tanpa merubah source code kita. kelebihan array dibanding linkedllist, array memilki data yang terurut sehingga mudah diakses, dan pengaturanya, namun memilki kekurangan pada jumlah memoriya yang statis, sedangkan linkedlist sulit dalam pengaksesanya namun fleksible dalam mengalokasikan memori....

berikut ini adalh contoh linkedlist dalam pemrograman java....

/*
This program Implement about Linked List
Include program
RemoveFirst RemoveLast AddFirst Addlast
InsertAfter InsertBefore Display Find
Author : huda
e-mail : huda890@gmail.com
*/
/*this class implement Node from a linked list*/
public class Node {
int Volume;
Node next;
public Node()
{
Volume=0;
Node next=null;
}
public void displayNode() {
System.out.println(Volume);
}
}
/*this class handle of clas Node*/
import java.io.*;
public class LinkedList {
public Node head;
private Node tail;
private Node cursor;
private Node Help;
/*this methode used to display volume of Node*/
public void Display()
{
cursor=head;
while(cursor!=null)
{
System.out.println("("+cursor.Volume+")");
cursor=cursor.next;
}
}
/*this is constructor*/
public LinkedList() {
head=null;
tail=null;
cursor=null;
Help=null;
}
/*this methode used for check the LinkedList Empty or Not*/
public boolean Empty()
{
if(head==null)
return(true);
return(false);
}
/*this methode used for find the volume of Node*/
public int find(int object)
{
int flag=1;
cursor=head;
while(cursor.Volume!=object && cursor.next!=null)
{
cursor=cursor.next;
flag++;
}
if(cursor.Volume!=object && cursor.next==null)
{
System.out.println("Not Found !!");
return(1);
}
else
{
System.out.println("Found In Index "+flag);
flag=-1;
}
return(flag);
}
/*this methode used for Add Node to the last Node*/
public Node AddLast(int object)
{
Node New_Node=new Node();
New_Node.Volume=object;
if(head==null)
{
head=New_Node;
tail=New_Node;
}
else
{
tail.next=New_Node;
tail=New_Node;
}
return(head);
}
/*this methode used to Add to first element of Linked List*/
public Node AddFirst(int object)
{
Node New_Node=new Node();
New_Node.Volume=object;
if(head==null)
{
head=New_Node;
tail=New_Node;
}
else
{
Help=head;
head=New_Node;
New_Node.next=Help;
}
return(head);
}
/*this methode used to remove first element of Linked List*/
public Node RemoveFirst()
{
if(Empty())
{
System.out.println("Empty!! !!");
return(null);
}
else
{
Help=head;
head=head.next;
Help.next=null;
}
return(head);
}
/*this methode used for remove the Last Element of LinkedList*/
public Node RemoveLast()
{
cursor=head;
if(Empty())
{
System.out.println("Empty!! !!");
return(null);
}
else
{
if(cursor.next==null)
RemoveFirst();
else
{
while(cursor.next.next!=null)
{
cursor=cursor.next;
}
cursor.next=null;
tail=null;
tail=cursor;
}
}
return(head);
}
/*this methode used to Remove the specific Node from the LinkedList*/
public Node RemoveKey(int object)
{
cursor=head;
if(Empty())
{
System.out.println("Empty!!");
return(null);
}
else
{
if(cursor.Volume==object)
RemoveFirst();
else
{
while(cursor.next.Volume!=object)
{
cursor=cursor.next;
}
if(cursor.next.next==null)
RemoveLast();
else
{
Help=cursor.next.next;
cursor.next.next=null;
cursor.next=Help;
}
}
}
return(Help);
}
/*this methode used to Insert a Node between two Node after specific Node*/
public Node InsertAfter(int Sort) throws IOException
{
cursor=head;
if(head==null)
{
System.out.println("Empty!!!");
return(null);
}
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Insert Volume :");
String temporary=input.readLine();
int object=Integer.parseInt(temporary);
int y=find(Sort);
if(y!=-1)
{
System.out.println("Not Found");
}
else
{
while(cursor.Volume!=Sort && cursor.next!=null)
{
cursor=cursor.next;
}
if(cursor.next==null)
{
AddLast(object);
}
else
{
Node New_Node=new Node();
New_Node.Volume=object;
Help=cursor.next;
cursor.next=New_Node;
New_Node.next=Help;
}
}
return(null);
}
/*this methode used to Insert a Node between two Node after specific Node*/
public Node InsertBefore(int Sort) throws IOException
{
if(head==null)
{
System.out.println("Empty!!!");
return(null);
}
int y=find(Sort);
if(y!=-1)
{
System.out.println("Not Found");
return(null);
}
cursor=head;
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Insert Volume :");
String temporary=input.readLine();
int object=Integer.parseInt(temporary);
Node New_Node=new Node();
New_Node.Volume=object;
if(head.Volume = = Sort)
{
AddFirst(object);
}
else
{
while(cursor.next.Volume!=Sort && cursor.next.next!=null)
{
cursor=cursor.next;
}
Help=cursor.next;
cursor.next=New_Node;
New_Node.next=Help;
}
return(null);
}
}
/*this clas the main class to handle second class*/
import java.io.*;
class main
{
public static void main(String[] args) throws IOException
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
Node node = new Node();
LinkedList list=new LinkedList();
int Answer=1;
while(Answer = =1)
{
System.out.println("Choose the methode :");
System.out.println("1.AddFirst");
System.out.println("2.AddLast");
System.out.println("3.Find");
System.out.println("4.RemoveFirst");
System.out.println("5.RemoveLast");
System.out.println("6.RemoveKey");
System.out.println("7.InsertAfter");
System.out.println("8.InsertBefore");
System.out.println("9.Display");
System.out.println("10.exit");
System.out.print("insert your choose :");
String temporary=input.readLine();
int choosen=Integer.parseInt(temporary);
switch(choosen)
{
case 1 : System.out.print("Insert Number :");
temporary=input.readLine();
choosen=Integer.parseInt(temporary);
list.AddFirst(choosen);break;
case 2 : System.out.print("Insert Number :");
temporary=input.readLine();
choosen=Integer.parseInt(temporary);
list.AddLast(choosen);break;
case 3 : list.Display();
System.out.print("Insert the Volume you want display:");
temporary=input.readLine();
choosen=Integer.parseInt(temporary);
list.find(choosen);break;
case 4 : list.RemoveFirst();break;
case 5 : list.RemoveLast();break;
case 6 : System.out.print("Insert Key :");
temporary=input.readLine();
choosen=Integer.parseInt(temporary);
list.RemoveKey(choosen);break;
case 7 : System.out.print("Insert Setelah :");
temporary=input.readLine();
choosen=Integer.parseInt(temporary);
list.InsertAfter(choosen);break;
case 8 : System.out.print("Insert Number :");
temporary=input.readLine();
choosen=Integer.parseInt(temporary);
list.InsertBefore(choosen);break;
case 9 : list.Display();break;
case 10: Answer=2;break;
default : System.out.println("Astaghfirullah!!!");break;
}
}
}
}

Send and Receive Message

Posted by Bl4ckB0y On 22.53 0 comments

tipntrick-computer.blogspot.com


source code berikut ini mengimplemntasikan tentang bagaimana sebuah proses dalam sistem operasi menerima dan mengirim pesan .....

permasalhanya sebagai berikut :
Indonesia akan mengikuti lomba lari estafet dalam olimpiade beijing 2008, simulasikan dengan menggunkan sebuah parent proses yang mengcreate 5 anak proses yang mana anak proses tersebut akan di representasikan sebagai 5 orang yang sedang berlari, pertama tongkat estafet bertuliskan "Praktikum Sisop 2008" dibawa oleh Debian, lalu Ubuntu, Mandrive Suse dan terakhir ke Dewalinux lalu kembali lagi ke Debian begitu seterusnya....?

=======================================================================================
#include "stdlib.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/ipc.h"
#include "sys/msg.h"
#include "stdio.h"
#include "string.h"
#define MSGSZ 30
#define FROMDEBIAN 1
#define FROMUBUNTU 2
#define FROMMANDRIVA 3
#define FROMSUSE 4
#define FROMDEWALINUX 5
#define TODEBIAN 5
#define TOUBUNTU 1
#define TOMANDRIVA 2
#define TOSUSE 3
#define TODEWALINUX 4
typedef struct msgbuf {
long mtype;
char mtext[MSGSZ];
} message_buf;

void debian();
void ubuntu();
void mandriva();
void suse();
void dewalinux();

int main(){
int s=0;
if(fork()==0){
debian();
}else{
if(fork()==0){
ubuntu();
}else{
if(fork()==0){
mandriva();
}else{
if(fork()==0){
suse();
}else{
if(fork()==0){
dewalinux();
}else{
int s;
printf("OLIMPIADE BEIJING 2008 LOMBA LARI ESTAFET\n\n");
printf("AMBIL POSISI : 1 2 ........ ");
scanf("%d",&s);
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
if (0>(msqid = msgget(key, msgflg )) ) {
perror("msgget");
return(1);
}
sbuf.mtype = TODEBIAN;
strcpy(sbuf.mtext, "Praktikum Sisop 2008");
buf_length = strlen(sbuf.mtext) + 1 ;
if (0>msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) ) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
return(1);
}
}
}
}
}
}
return(0);
}

void debian(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
int i=0;
while(3>i){
if ( 0>(msqid = msgget(key, 0666))) {
printf("tidak mendapat pesan \n\n");
return;
}
i++;
if (0> msgrcv(msqid, &sbuf, MSGSZ, FROMDEWALINUX, 0)) {
printf("TIDAK menerima pesan \n\n");
return;
}
/*melakukan jawaban atas pesan yang diterima*/
printf("(%s) ---> DEBIAN(%d) ", sbuf.mtext,getpid());
/*mencoba mengirim pesan kepada UBUNTU*/
if (0>(msqid = msgget(key, msgflg )) ) {
perror("msgget");
return;
}
/*berhasil meminta slot pesan untukdiberikan ke ubuntu*/
sbuf.mtype = TOUBUNTU;
buf_length = strlen(sbuf.mtext) + 1 ;
if (0>msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) ) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
return;
}else{ printf(" lanjut UBUNTU \n");}
}
}

void ubuntu(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
int i=0;
for(i=0;3>i;i++){
if (0>(msqid = msgget(key, 0666)) ) {
perror("error dalam mendapatkan pesan (msgget)");
return;
}

/*menerima pesan dari DEBIAN*/
if (0>msgrcv(msqid, &sbuf, MSGSZ, FROMDEBIAN, 0)) {
perror("eror saat penerimaan pesan : msgrcv");
return;
}

/*melakukan jawaban atas pesan yang diterima*/
printf("(%s) di UBUNTU (%d) ", sbuf.mtext,getpid());

/*mencoba mengirim pesan kepada MANDRIVA*/
if (0>(msqid = msgget(key, msgflg ))) {
perror("msgget");
return;
}
/*berhasil meminta slot pesan untukdiberikan ke ubuntu*/
sbuf.mtype = TOMANDRIVA;
buf_length = strlen(sbuf.mtext) + 1 ;
if (0>msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) ) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
return;
}else{ printf(" Lanjut MANDRIVA \n", sbuf.mtext);}
}
}


void mandriva(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
int i=0;
for(i=0;3>i;i++){
if (0>(msqid = msgget(key, 0666))) {
perror("error dalam mendapatkan pesan (msgget)");
return;
}

/*menerima pesan dari DEBIAN*/
if (0>msgrcv(msqid, &sbuf, MSGSZ, FROMUBUNTU, 0) ) {
perror("eror saat penerimaan pesan : msgrcv");
return;
}

/*melakukan jawaban atas pesan yang diterima*/
printf("(%s) di MANDRIVA (%d) ", sbuf.mtext,getpid());

/*mencoba mengirim pesan kepada MANDRIVA*/
if (0>(msqid = msgget(key, msgflg )) ) {
perror("msgget");
return;
}
/*berhasil meminta slot pesan untukdiberikan ke ubuntu*/
sbuf.mtype = TOSUSE;
buf_length = strlen(sbuf.mtext) + 1 ;
if (0>msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) ) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
return;
}else{ printf(" Lanjut SUSE \n", sbuf.mtext);}
}
}

void suse(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
int i=0;
for(i=0;3>i;i++){
if (0>(msqid = msgget(key, 0666)) ) {
perror("error dalam mendapatkan pesan (msgget)");
return;
}

/*menerima pesan dari DEBIAN*/
if (0>msgrcv(msqid, &sbuf, MSGSZ, FROMMANDRIVA, 0) ) {
perror("eror saat penerimaan pesan : msgrcv");
return;
}

/*melakukan jawaban atas pesan yang diterima*/
printf("(%s) di SUSE (%d) ", sbuf.mtext,getpid());

/*mencoba mengirim pesan kepada MANDRIVA*/
if (0>(msqid = msgget(key, msgflg )) ) {
perror("msgget");
return;
}
/*berhasil meminta slot pesan untukdiberikan ke ubuntu*/
sbuf.mtype = TODEWALINUX;
buf_length = strlen(sbuf.mtext) + 1 ;
if (0>msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) ) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
return;
}else{ printf(" LanjutDEWALINUX \n", sbuf.mtext);}
}

}

void dewalinux(){
int msqid;
int msgflg = IPC_CREAT | 0666;
key_t key;
message_buf sbuf;
size_t buf_length;
key = 1234;
int i=0;
for(i=0;3>i;i++){
if (0>(msqid = msgget(key, 0666)) ) {
perror("error dalam mendapatkan pesan (msgget)");
return;
}
/*menerima pesan dari DEBIAN*/
if (0>msgrcv(msqid, &sbuf, MSGSZ, FROMSUSE, 0) ) {
perror("eror saat penerimaan pesan : msgrcv");
return;
}
/*melakukan jawaban atas pesan yang diterima*/
printf("(%s) di DEWALINUX (%d) ", sbuf.mtext,getpid());
if(i==2){
printf("\nFinish !!!! Allhamdulillah !!! juara 1 dari 1 peserta !!!\n");
return;
}
/*mencoba mengirim pesan kepada Debian*/
if (0>(msqid = msgget(key, msgflg )) ) {
perror("msgget");
return;
}
/*berhasil meminta slot pesan untukdiberikan ke debian*/
sbuf.mtype = TODEBIAN;
buf_length = strlen(sbuf.mtext) + 1 ;
if (0>msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) ) {
printf ("%d, %d, %s, %d\n", msqid, sbuf.mtype, sbuf.mtext, buf_length);
perror("msgsnd");
return;
}else{ printf(" Putar ke DEBIAN \n", sbuf.mtext);}
}
}

=======================================================================================

begitulah source code buatan saya, mohon maaf jika ada kesalahan...
buat teman-teman satu praktikum dengan saya....MBACEM YO MBACEM REK TAPI DIPELAJARI..

Struct Using C

Posted by Bl4ckB0y On 19.46 0 comments

Studebt Database
/*
this program using dev C++
you can apply this program to visual C++
it use to make symple record about data of student
you can develop it to make big program
by develop the functions and the add the struct
it is just for fun
*/
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#define MAX 20
#define MIN 11
/*Prototipe of struct*/
typedef struct
{
char name[MAX]; /*it is the part of struct student*/
char number[MIN];/*it is the part of struct student*/
}student;
/*this function to make new file an automatically open the file*/
void make_new(char name[20])
{
puts("Please Type the File Name with the extention :");/*it type messege to konsole
(DOS) */
gets(name);/*it insert the of file to name variabel*/
FILE *ptr; /*it is pointer to file*/
ptr=fopen(name,"wb"); /*pointer to file ptr point to file (name) (created the file)*/
fclose(ptr); /*pointer to file escape from point to file (name)*/
puts("File was created !!"); /*it type to messege to konsole (DOS) */
}
/*this functions to fill up the file*/
int fill_up(char name[20])
{
FILE *ptr; /*declarations of pointer*/
if((ptr=fopen(name,"rb+"))==NULL) /*pointer ptr point ot the file (name) using read
binary mode*/
{puts("File not Found ????"); /*it type to messege to konsole (DOS) */
return(0);} /*return to the main function*/
int k; /*it the sum of student in the file*/
k=getw(ptr); /*it take the sum of number in the file*/
printf("it found %d Record\n\n",k); /*it type the sum of student in konsole*/
if(k==-1) /*if the sum of student (k) is (-1) that meaning the file is empty*/
{k=0;fwrite(&k,sizeof(k),1,ptr);}
else{fclose(ptr);ptr=fopen(name,"ab+");} /*change the mode of operation into make,
write, and read*/
student study; /*it declare the anymous of struct student*/
int sum; /*it type to konsole about sum of student which added to file*/
printf("please insert Sum of Student : ");
scanf("%d",&sum); /*get the sum of student*/
fflush(stdin); /*clear the buffer*/
for(int j=0;sum>j;j++) /*iterate until number of sum of student which added to file*/
{
printf("Name : ");
gets(study.name); /*take the name of student*/
printf("Number: ");
gets(study.number); /*take the number of student*/
fwrite(&study,sizeof(study),1,ptr); /*write the name and number of student to
file*/
system("cls"); /*clear the console*/
}
fclose(ptr); /*close the file pointer*/
k=k+sum; /*sum of the new student added to the file*/
ptr=fopen(name,"rb+"); /*open the file again*/
fwrite(&k,sizeof(k),1,ptr); /*write the new sum of student to file*/
fclose(ptr); /*close the file pointer and return to the main*/
}
/*this function to read the data in the file*/
int read_data(char name[20])
{
student study; /*declare of the struct using initialize*/
FILE *ptr; /*file pointer*/
if((ptr=fopen(name,"rb"))==NULL) /*if file (name) not found function return to the
main*/
{puts("File not Found ?");return(0);}
int sum; /*it is sum of student in the file */
sum=getw(ptr); /*take integer data from file*/
printf("it %d Record\n\n",sum);
if(sum==-1) /*if the file is empty function return to the main*/
{puts("file is Empty???");return(0);}
for (int j=0;sum>j;j++) /*looping until sum of student*/
{
fread(&study,sizeof(study),1,ptr);
printf("%s\t%s\n",study.number,study.name);
}getch(); /*to stop until user press a key*/
system("cls"); /*clean the konsole screen*/
fclose(ptr); /*close the file pointer*/
}
/*this funtions to sort the data (record) by number*/
int sort_number(char name[20])
{
student temp ; /*it use for temporary variable using typedata struct*/
student study[10]; /*maksimum numberof student is 10, it is array of struct*/
FILE *ptr; /*file pinter*/
if((ptr=fopen(name,"rb"))==NULL) /*if ptr not found it return NULL */
{puts("file not Found");return(0);}
int sum; /*it is the sum of student in the file*/
sum=getw(ptr); /*get integer from file */
if(sum==-1) /*if the sum is (-1) the file must be Empty*/
{puts("file Empty ???");return(0);}
for (int j=0;sum>j;j++) /*load the data to the memory*/
{
fread(&temp,sizeof(temp),1,ptr); /*read data from the file*/
for(int i=0;MAX>i;i++)
{
study[j].name[i]=temp.name[i] ; /*load (name) to real struct */
}
for(int i=0;MIN>i;i++)
{
study[j].number[i]=temp.number[i]; /*load (number) to real struct*/
}
}
/*Sorting Process*/
/*it using bublesor,t you can use other sorting methode*/
for(int j=0;sum>j;j++)
{
for(int i=j+1;sum>i;i++)
{
int y=strcmp(study[j].number,study[i].number); /*compare the number*/
if(y==1)
{ /*Swaping system*/
/*because C cannot load from any array element to the another array
element*/
/*we must load it one by one*/
/*First step*/
/*load the j element to temporary element*/
for(int u=0;MAX>u;u++)
{
temp.name[u]=study[j].name[u];
}
/*the number must load too*/
for(int u=0;MIN>u;u++)
{
temp.number[u]=study[j].number[u];
}
/*second*/
/*load the i element to j element*/
for(int u=0;MAX>u;u++)
{
study[j].name[u]=study[i].name[u];
}
/*the number must load too*/
for(int u=0;MIN>u;u++)
{
study[j].number[u]=study[i].number[u];
}
/*third*/
/*load the temporary element to the i element*/
for(int u=0;MAX>u;u++)
{
study[i].name[u]=temp.name[u];
}
/*the number must load too*/
for(int u=0;MIN>u;u++)
{
study[i].number[u]=temp.number[u];
}
/*after this the element from j can swap to i, and i can swap to j*/
}
}
}
/*after all element was done to sort now we can print it to the screen*/
for(int k=0;sum>k;k++)
{
printf("%s\t%s\n",study[k].number,study[k].name);
}
fclose(ptr);
}
/*this function like the sort_number but we compare the name to sort the file*/
int sort_name(char name[20])
{
student temp;
student study[10];
FILE *ptr;
if((ptr=fopen(name,"rb"))==NULL)
{puts("file not found ?");return(0);}
int sum;
sum=getw(ptr);
printf("it found %d Record\n\n",sum);
if(sum==-1)
{puts("empty file ???");return(0);}
for (int j=0;sum>j;j++)
{
fread(&temp,sizeof(temp),1,ptr);
for(int i=0;MAX>i;i++)
{
study[j].name[i]=temp.name[i];
}
for(int i=0;MIN>i;i++)
{
study[j].number[i]=temp.number[i];
}
}
/*massage*/
for(int j=0;sum>j;j++)
{
for(int i=j+1;sum>i;i++)
{
int y=strcmp(study[j].name,study[i].name);
if(y==1)
{
/*first*/
for(int u=0;MAX>u;u++)
{
temp.name[u]=study[j].name[u];
}
for(int u=0;MIN>u;u++)
{
temp.number[u]=study[j].number[u];
}
/*second*/
for(int u=0;MAX>u;u++)
{
study[j].name[u]=study[i].name[u];
}
for(int u=0;MIN>u;u++)
{
study[j].number[u]=study[i].number[u];
}
/*third*/
for(int u=0;MAX>u;u++)
{
study[i].name[u]=temp.name[u];
}
for(int u=0;MIN>u;u++)
{
study[i].number[u]=temp.number[u];
}
}
}
}
for(int k=0;sum>k;k++)
{
printf("%s\t%s\n",study[k].number,study[k].name);
}
fclose(ptr);
}
/*thhis funtion to delete the record*/
int delete_data(char name[20])
{
student study; /*declare variabel study using type student (struct)*/
FILE *ptr;
if((ptr=fopen(name,"rb+"))==NULL)
{puts("file not found ?");return(0);}
int sum;
sum=getw(ptr);
printf("it found %d Record\n\n",sum);
if(sum==-1)
{puts("file is Empty ???");return(0);}
puts("file opened");
puts("Insert the Index : "); /*ask the number of index wan to be deleted*/
int y;scanf("%d",&y); /*take the number of index*/
if(y>sum){puts("index not found !!!");return(0);} /*if the index more big than sum,
return to teh main*/
fseek(ptr,sizeof(study)*(sum-1)+sizeof(int),SEEK_SET); /*slide pointer file to the last
element*/
fread(&study,sizeof(study),1,ptr); /*read the last element*/
fseek(ptr,sizeof(study)*(sum-y)+sizeof(int),SEEK_SET); /*slide the pointer too the
element which to be deleted*/
fwrite(&study,sizeof(study),1,ptr); /*write to the last element to the element which to
be deleted*/
sum--; /*sum decrement by 1*/
fseek(ptr,0,SEEK_SET);/*slide the pointer to the number of sum*/
fwrite(&sum,sizeof(sum),1,ptr);/*write the new sum in the file*/
fclose(ptr);/*close file*/
}
/*take the name of file*/
int open_file(char name[20])
{
puts("enter the file name and the extentions : ");
gets(name);
return(0);
}
/*it is the main function*/
main(void)
{char answer;
char name[20];
do
{
puts("type your choose: ");
puts("1.make new file");
puts("2.insert Data");
puts("3.sort by Name");
puts("4.sort by number");
puts("5.Delete Data");
puts("6.Read Data");
puts("7.Open File");
char choose;
choose=getch(); /*tkae the user choose*/
system("cls");
switch(choose) /*switch the user choose*/
{
case '1' : make_new(name);break;/*go to make new function*/
case '2' : fill_up(name);break;/*go to fill up function*/
case '3' : sort_name(name);break;/*go to sort by name function*/
case '4' : sort_number(name);break;/*go to sort by number function*/
case '5' : delete_data(name);break;/*go to delete funtion*/
case '6' : read_data(name);break;/*go to read data function*/
case '7' : open_file(name);break;/*go to oen file function*/
default : puts("that's wrong ??");
}
puts("press y for return!");
answer=getch();/*get the answer*/
}
while(answer=='y'||answer=='Y');/*repeat program if type yes (y/Y)*/
system("cls");
puts("Thank for use our software !!");
getch();
}

Invers Matrix

Posted by Bl4ckB0y On 17.24 0 comments

THE INVERS OF MATRIX USING GAUSS-JORDAN METHODE
/* CALCULATE THE INVERS OF MATRIX USING GAUSS-JORDAN METHODE*/
/*it compile using devC++ you, it implement methode of gauss jordan to invers matrix*/
#include "stdio.h"
#include "conio.h"
main(void)
{ int p[20], a[20][20], t;
int m, i, j, k, x;
printf("\ninsert size of matrix : \n");
scanf("%d", &m);
printf("\ninsert the matrix element step by step");
/* read the matrix */
for(i=1; i<=m; i++)
{ printf("\n");
for(j=1; j<=m; j++)
{ printf("A(%d,%d)= ",i, j);
scanf("%d", &a[i][j]);
}
}
/* print the matrix to konsole*/
printf("\nthe matrix: ");
for(i=1; i<=m; i++)
{ printf("\n");
for(j=1; j<=m; j++)
printf(" %2d", a[i][j]);
}
/* invertions proses */
for(i=1; i<=m; i++)
{ p[i] = a[i][j];
a[i][j] = 1;
for(j=1; j<=m; j++)
{ a[i][j] = a[i][j]/p[i];
}
for(k=1; k<=m; k++);
{ if(k != i)
{ t = a[k][i];
a[k][i] = 0;
for(x=1; x<=m; x++)
a[k][x] = a[k][x] - a[i][x] * t;
}
}
}
/* print the invertions matrix to konsole*/
printf("\n\invertion matrix : \n");
for(i =1; i <=m; i++)
{ for(j=1; j<=m; j++)
printf(" %d", a[i][j]);
printf(" \n");
}
getch();
}

Combination and Permutation

Posted by Bl4ckB0y On 17.21 0 comments

Permutation And Combination using C
*Permutation an Combination
this program to found permutation and combination of number
using C, we contruct using DevC++, you can use visual C, turbo C and many other
but maybe some funtion is not working
we recomended using DevC++ v 4.9
*/
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#define MAX 20
/*it is function to calculate the permutation and combination using factorial*/
int factorial(int q)
{
if (q==0)
return(1);
else
return(q*factorial(q-1));/*this recursive funtions*/
}
/*this function to calculate the permutation*/
void permutation()
{
system("cls");/*clear konsole */
printf("\tPermutation and Combination\n");
printf("\t===========================\n\n");
char string[MAX];/*declare of array*/
printf("input : ");
gets(string);/*take the string for string*/
int long_of_string = strlen(string);/*to get the long of the string, it use for looping*/
int flag=0;/*it for flag and index the 'p' position in the array*/
for(int i=0;i {
if(string[i]=='p' || string[i]=='P')/*try to find identifier p*/
{
flag=i;break;/*save the index of p in the array to flag*/
}
}
if(flag!=0)/*if the char p was found*/
{
int firts_number=atoi(string);/*convert the first number until char p*/
int second_number= atoi(&string[flag+1]);/*convert the second number begin from
char p*/
if(firts_number>=second_number)
{
int factorial_first_number=factorial(firts_number);/*calculate factorial of
first_number*/
int factorial_second_number=factorial(second_number);/*calculate factorial of
second_number*/
printf("output : %d\n\n",factorial_first_number/factorial_second_number);/*display
permutation of firts and second number*/
}
else {printf("output : Imposible\n\n");}/*if the first number less than the second
number that imposible to permutation*/
}
else{printf("\nWrong\n");}/*if the comand without p indentity, it display wrong
messege*/
}
/*this functions to calculate the combination*/
void combination()
{
system("cls");
printf("\tpermutation and combination\n");
printf("\t===========================\n\n");
char string[MAX];
printf("input : ");
gets(string);
int long_of_string = strlen(string);/*calculate the long of string*/
int flag=0;/*it variabel to take index of char 'c' in the array*/
for(int i=0;long_of_string>i;i++)/*looping for found 'c'*/
{
if(string[i]=='c' || string[i]=='C')/*if found char c*/
{
flag=i;break;
}
}
if(flag!=0)
{
int firts_number=atoi(string);/*convert the first number until char p*/
int second_number= atoi(&string[flag+1]);/*convert the second number begin from
char p*/
if(firts_number>second_number)
{
int factorial_of_third_number=factorial(firts_number-second_number);
int factorial_of_firts_number=factorial(firts_number);
int factorial_of_second_number=factorial(second_number);
printf("output : %d\n\n", factorial_of_firts_number/(factorial_of_third_number*
factorial_of_second_number));
}
else {printf("output : imposible\n\n");}/*if the first number less than the second
number that imposible to permutation*/
}
else{printf("\nwrong code\n");}/*if the comand without p indentity, it display wrong
messege*/
}
/*this is the main program*/
main(void)
{ char u;
do
{
system("cls");
printf("\tpermutation and combination\n");
printf("\t===========================\n\n");
printf("1.PERMUTATION (ex : 12p5)\n2.COMBINATION (ex : 5c2 )\n\n");
printf("ENTER YOUR CHOOSE : ");
char p;
p=getch();/*try to take the choose of user*/
switch(p)
{
case '1' : permutation();break;/*go to permutation function*/
case '2' : combination();break;/*go to combination function*/
default : printf("\nWRONG\n");break;
}
printf("PRESS Y FOR REPEAT : ");
u=getch();/*stop until user press any key*/
}while(u=='y'||u=='Y');
}

Binary Search

Posted by Bl4ckB0y On 17.17 0 comments

Binary Search
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "stdlib.h"
/*this is funtion binary search, this funtion search a element
using the middle element as pivot and the element divided into 2 sub element
left elements are the element which less than pivot
right elements are the element which more than pivot
so the array must be sort before to use this function
if the search element more than pivot,
it will divide the right element and take the middle element of
right element as pivot, so will left element*/
void search(int array[20],int value,int cari,int pivot)
{
if(cari > array[pivot] && array [pivot] != '\0' && pivot>=0 && pivot<=value)/*it
define the right element*/
{
pivot=(value-pivot)/2+pivot;
search(array,value,cari,pivot);
}
else
if(array[pivot]>cari && array[pivot] !='\0' && pivot>=0 && value>=pivot) /*it define
the left element*/
{
value=pivot;
pivot=value/2;
search(array,value,cari,pivot);
}
else
if (cari == array[pivot]) /*it the pivot, program stop until the subject same with pivot
or not found int anoather*/
{printf(" \n found in index %d ",pivot+1);}
else
{printf("\n NOT FOUND!!!");}
}
/*this function to swap array*/
void swap(int array[20], int i, int p)
{
int g;
g=array[i];
array[i]=array[p];
array[p]=g;
}
/*this funtion to print array after the element sorted*/
void print(int array[20], int n)
{
for (int i=0;n>i;i++)
{
printf("%3d ",array[i]);
}
}
/*this function is selection sort you can use another sorting like buble sort*/
void selection(int array[20], int n)
{
int p;
for(int i=0;n-1>=i;i++)
{
p=i;
for(int j=1+i;n>j;j++)
{
if(array[p]>array[j])
{p=j;}
swap(array,i,p); /*to swap element of array*/
}
}
print(array,n);
}
/*this funtion to get input array from user*/
int input(int array[20])
{
int k;
printf("how much the array : ");
scanf("%d",&k);
for (int i=0;k>i;i++)
{
printf("insert array [%d] : ",i);
scanf("%d",&array[i]);
}
selection(array,k);
return(k);
}
/*this is the m,ain program*/
main(void)
{
printf("Binary Search Program\n");
int array[20],value,cari,pivot;
/*value is long of array*/
/*cari is the element want to search*/
/*i is pivot element*/
value=input(array);
pivot=value/2;
printf("\n\nplease, your choose : ");
scanf("%d",&cari);
search(array,value,cari,pivot);
fflush(stdin);
getch();
getch();
}

Iteration

Posted by Bl4ckB0y On 17.12 0 comments

/*play with looping*/
/*it compile using DevC++, it just for fun, play with programing*/
#include"stdio.h"
#include "conio.h"
main(void)
{
int a,b,c;
printf("insert the number of looping = ");
scanf("%d",&a);
for(b=a;b>=1;b--)
{
for(c=b;c>=1;c--)
{
printf("*");
}
printf("\n");
}
for(b=2;a>=b;b++)
{
for(c=0;c>=c-1;c++)
{
printf("*");
}
printf("\n");
}
getch();
}

Membuat Anak Proses

Posted by Bl4ckB0y On 16.57 0 comments

source code berikut ini mengimplementasikan bagaimana cara membuat sebuah anak proses, permasalahanya sebagai berikut, sebuah program akan membuat anak proses yang membalik sebuah string dari induk prosesnya.., setelah itu anak program akan mengirim kembali string yang sudah terbalik tadi ke induk proses untuk ditampilkan ke layar....?

untuk menyelesaikanya, kita butuh 2 alat yaitu pipe dan fork, pipe digunakan untuk mengirim data dari anak ke induk dan fork digunakan untuk membuat anak proses...
=====================================================================================
#include "stdio.h"
#include "string.h"
#include "sys/types.h"
#include "unistd.h"

int main(void) {
char masukan[64]; //string yang akan dibalik
char hasil_balikan[64]; //hasil balikan string
int pipa_penghubung[2]; //pipe untuk alat penghubung
printf("Masukkan input : ");
scanf("%s",&masukan);
pipe(pipa_penghubung); //inisialisasi pipe
int pid=fork(); //membuat anak proses
if ( pid== 0){
/*anak proses melakukan pembalikan*/
close(pipa_penghubung[0]); //pipa pembaca (INDEKS KE 0) ditutup;
int y=0;
int x=strlen(masukan)-1; //menghitung panjang string
while (x>=0){
hasil_balikan[y++] = masukan[x--]; //proses pembalikan
}
FILE *tulis = fdopen(pipa_penghubung[1],"w"); //membuka pipa penulis dan memasukanya ke pointer Buffer FILE
fprintf(tulis,"%s",hasil_balikan); //menulis hasil_balikan ke pointer buffer;
fclose(tulis); //pointer tulis FILE ditutup;

}
else
{
close(pipa_penghubung[1]); //menutup pipa penulis
FILE *baca = fdopen(pipa_penghubung[0],"r"); //membuka pipa pembaca dan memasukanya ke pointer Buffer FILE
fscanf(baca,"%s",hasil_balikan); //memasukan pointer isi pointer buffer file ke hasil_balikan
fclose(baca); //menutup pointer buffer FILE
hasil_balikan[strlen(masukan)]='\0'; //manambah null terminator
printf("Hasil Pembalikan : %s\n",hasil_balikan); //menulis hasil balikan ke layar
close(pipa_penghubung[0]); //menutup pipa pembaca
}
return(0);
}

Random and Randomize

Posted by Bl4ckB0y On 05.24 0 comments

/*
We using Dev C++ v 6.0 to make the source codes
Author : Nurul Huda
e-mail : h2d4890@gmail.com
*/
/*using Random and randomize*/
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "time.h"
/*this function just for palying with programing using C
this program implement random and randomize to make a number
from 0 until 100 and the user must found the number*/
void main()
{
int e;
do{system("cls");
int a,b;
srand((unsigned) time(0));
a=rand()%100;
//printf("\n %d\n",a); //if you want to win. active this function
do{
fflush(stdin);
printf("Insert Number= ");
scanf("%d",&b);
if(b>a)
{
printf("Less\n"); /*the number is too big*/
}
else if (a>b) {printf("More\n");} /*the number is to small*/
else {printf("ok\n");} /*found the number*/
}
while(a!=b);
printf("Congratulation!\n");
printf("Try Again (1=yes) ");
scanf("%d",&e);
}
while(e==1);
}

your Ads Here

Your Ad Here FellowEquality.com