Minggu, 23 Maret 2014

Contoh Aplikasi STRING.

Assalamualikum BLOGers .. 

Nama            : Arifah Hidayah

Nim               : 12.2c.06

 

 

 

 

 

 Narsis dulu ia he,,,,he.

"Contoh Aplikasi Program String "

Berikut Contoh program (String) :

strcpy :
 

#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>

main()
{
    char asal[100];
    char hasil[100];
    clrscr();
    cout<<"Masukan kalimat : "; gets(asal);
    strcpy(hasil,asal);cout<<endl;
    cout<<"Kalimat asal  : "<<asal<<endl;
    cout<<"Kalimat hasil : "<<hasil<<endl;
getch();
}
 
 
Strcat : 

#include <stdio.h>
#include <conio.h>
#include <string.h>
 
main()
 
{
char str[80];
strcpy (str,"bsi ");
//mulai menggabungkan string
strcat(str,"kramat 18 ");
strcat(str,"senen ");
strcat(str,"jakarta pusat.");
//mulai menggabungkan string
puts (str);
getche();
}
 
Strcmp :
 
#include <iostream.h>
#include <string.h> 

void main ()

{
     int hasil;
     char str1 [20];
     char str2 [20];
     cout<<"Input String1 : " ;cin>>str1;
     cout<<"Input String2 : " ;cin>>str2;
     hasil = strcmp (str1,str2) ;
     cout<<"Hasil Perbandingan = " <<hasil;
}

Strlen :


#include <stdio.h>
#include <string.h>

int main ()
{
   char str[50];
   int len;

   strcpy(str, "This is tutorialspoint.com");
   len = strlen(str);
   printf("Length of |%s| is |%d|\n", str, len);
   
   return(0);
}
 
 
Strchr :
 
 
#include <stdio.h>
#include <string.h>
#include <conio.h>

int main ()
{
  char str[] = "Bina Sarana Informatika";
  char * letak;

  printf ("Letak karakter 'a' pada posisi : \"%s\"...\n",str);
  letak=strchr(str,'a');

  while (letak!=NULL)
  {
    printf ("Ditemukan pada posisi : %d\n",letak-str+1);
    letak=strchr(letak+1,'a');   
  }

  getche();
}



 ~  Terima Kasih ^_^  ~