Selasa, 02 Juni 2015

Contoh Program Pengolahan String

1. mengecek apakah karakter C adalah huruf, bukan angka
#include<stdio.h>
#include<ctype.h>
int main(void)
{
char c='C';
if (isalpha(c))
printf("%c is alphabetic \n",c);
else printf("%c is not alphabetic \n",c);
return 0;
}



2.mengecek apakah karakter C adalah angka, bukan huruf
#include<stdio.h>
#include<ctype.h>
int main(void)
{
char c='C';
if (isdigit(c))
printf("%c is a digit \n",c);
else printf("%c is not a digit \n",c);
return 0;
}

3.mengecek apakah karakter C adalah huruf kecil
#include<stdio.h>
#include<ctype.h>
int main(void)
{
char c='C';
if (islower(c))
printf("%c is lower case character \n",c);
else printf("%c is not lower case character \n",c);
return 0;
}

4.mengecek apakah karakter C adalah huruf Kapital
#include<stdio.h>
#include<ctype.h>
int main(void)
{
char c='C';
if (isupper(c))
printf("%c is an upper case character \n",c);
else printf("%c is not an upper case character \n",c);
return 0;

}

5.Menukar dari str1 ke str2
#include<stdio.h>
#include<string.h>
int main(void)
{
char str1[10]={"abcdefghi"};
char str2[10];
strcpy(str2, str1);
printf("%s\n",str2);
return 0;
}

6.Menukar string lah pokoknya :) :)
#include<stdio.h>
#include<string.h>
int main(void)
{
char destination[25];
char blank[10]={""}, c[10]={"C++"}, Borland[10]={"Borland"};

strcpy(destination, Borland);
printf("%s\n",destination);

strcpy(destination, blank);
printf("%s\n",destination);

strcpy(destination, c);
printf("%s\n",destination);
return 0;
}
Share:

0 komentar:

Posting Komentar

index

Popular Posts