CONTOH PROGRAM STRCPY
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char kata1[100];
char kata2[100];
clrscr();
cout<<"Masukan kata:"; cin>>kata1;
strcpy(kata2,kata1);
cout<<"kata1 adalah:"<<kata1<<endl;
cout<<"kata2 adalah:"<<kata2<<endl;
getch();
}
CONTOH PROGRAM STRCAT
#include <stdio.h>
#include <conio.h>
#include <string.h>
using namespace std;
main()
{
char kalimat[120],
kata1[20]="Anda ",
kata2[20]="sedang ",
kata3[20]="berkunjung ",
kata4[20]="di ",
kata5[40]="Luthfi623blogspot.com";
strcpy (kalimat, kata1);
strcat (kalimat, kata2);
strcat (kalimat, kata3);
strcat (kalimat, kata4);
strcat (kalimat, kata5);
puts (kalimat);
getch();
}
CONTOH PROGRAM STRCMP
#include<stdio.h>
#include<string.h>
CONTOH PROGRAM STRCAT
#include <stdio.h>
#include <conio.h>
#include <string.h>
using namespace std;
main()
{
char kalimat[120],
kata1[20]="Anda ",
kata2[20]="sedang ",
kata3[20]="berkunjung ",
kata4[20]="di ",
kata5[40]="Luthfi623blogspot.com";
strcpy (kalimat, kata1);
strcat (kalimat, kata2);
strcat (kalimat, kata3);
strcat (kalimat, kata4);
strcat (kalimat, kata5);
puts (kalimat);
getch();
}
CONTOH PROGRAM STRCMP
#include <stdio.h>
#include <conio.h>
#include
<iostream.h>
main()
{
char nim[3],jur[15];
cout<<"Input
Nim =";cin>>nim;
if(strcmp(nim,"11")==0)
strcpy(jur,"Komputerisasi
akuntansi");
else
if(strcmp(nim,"12")==0)
strcpy(jur,"Manajemen
Informatika");
else
if(strcmp(nim,"13")==0)
strcpy(jur,"teknik
komputer");
else
strcpy(jur,"NIM
yang anda masukkan salah");
cout<<"jurusan
="<<jur<<endl;
getch();
}
CONTOH PROGRAM STRLEN
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "iostream.h"
main()
{
char huruf[70],pindah[70];
cout<<"Masukkan Kata : ";gets(huruf);
cout<<"Panjang Kata yang diinput : ";cout((strlen(huruf);
// tanda << di ganti dengan tanda (( dikarenakan tidak bisa //
// tampil jika menggunakan tanda << jadi ganti aj nanti :) //
getch();
}
#include "conio.h"
#include "string.h"
#include "iostream.h"
main()
{
char huruf[70],pindah[70];
cout<<"Masukkan Kata : ";gets(huruf);
cout<<"Panjang Kata yang diinput : ";cout((strlen(huruf);
// tanda << di ganti dengan tanda (( dikarenakan tidak bisa //
// tampil jika menggunakan tanda << jadi ganti aj nanti :) //
getch();
}
CONTOH PROGRAM STRCHR
#include<stdio.h>
#include<string.h>
int main ()
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...\n",str);
pch=strchr(str,'s');
while(pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...\n",str);
pch=strchr(str,'s');
while(pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}