is... tolower toupper
#include <stdio.h>
#include <ctype.h>
int main (int argc, char *argv[])
{
char *str = "A8@\033b\t,";
int i;
for ( i = 0; i < strlen(str); i++ )
{
if ( isalnum(str[i]) )
{
printf("%c is alnum\n",str[i]);
}
if ( isalpha(str[i]) )
{
printf("%c is alpha\n",str[i]);
}
if ( isascii(str[i]) )
{
printf("%c is ascii\n",str[i]);
}
if ( isblank(str[i]) )
{
printf("%c is blank\n",str[i]);
}
if ( iscntrl(str[i]) )
{
printf("%c is cntrl\n",str[i]);
}
if ( isdigit(str[i]) )
{
printf("%c is digit\n",str[i]);
}
if ( isgraph(str[i]) )
{
printf("%c is graph\n",str[i]);
}
if ( islower(str[i]) )
{
printf("%c is lower\n",str[i]);
}
if ( ispunct(str[i]) )
{
printf("%c is punct\n",str[i]);
}
if ( isprint(str[i]) )
{
printf("%c is print\n",str[i]);
}
if ( isupper(str[i]) )
{
printf("%c is upper\n",str[i]);
}
if ( isxdigit(str[i]) )
{
printf("%c is xdigit\n",str[i]);
}
}
return 0;
}
OUTPUT :
// A is alnum
// A is alpha
// A is ascii
// A is graph
// A is print
// A is upper
// A is xdigit
// 8 is alnum
// 8 is ascii
// 8 is digit
// 8 is graph
// 8 is print
// 8 is xdigit
// @ is ascii
// @ is graph
// @ is punct
// @ is print
// \033 is ascii
// \033 is cntrl
// b is alnum
// b is alpha
// b is ascii
// b is graph
// b is lower
// b is print
// b is xdigit
// is ascii
// is blank
// is cntrl
// , is ascii
// , is graph
// , is punct
// , is print
tolower
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int Isitsame (void);
// ////////////////////////////////////////////////
int main (int argc, char **argv)
{
int res;
res = Isitsame();
printf ("\n\t%d\n", res);
return 0;
}
OUTPUT :
// ////////////////////////////////////////////////
int Isitsame (void)
{
char *arr1, *arr2, *p1, *p2;
arr1 = malloc (256);
arr2 = malloc (256);
printf ("\nEnter first string : ");
fgets (arr1, 255, stdin);
fflush (stdin);
printf ("Enter second string: ");
fgets (arr2, 255, stdin);
fflush (stdin);
p1 = arr1; p2 = arr2;
while (*p1)
{
*p1 = tolower(*p1);
p1++;
}
while (*p2)
{
*p2 = tolower(*p2);
p2++;
}
printf ("\n%s", arr1);
printf ("%s", arr2);
if ( strcmp (arr1, arr2) == 0 )
return 1;
else
return 0;
}
OUTPUT :
// Enter first string : Hello
// Enter second string: HELLO
//
// hello
// hello
//
// 1
toupper
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int no_case_comp(char c1, char c2)
{
// return true (1) if equal
return toupper(c1) == toupper(c2);
}
OUTPUT :
// //////////////////////////////////////////
int main ( int argc, char *argv[] )
{
char s1[] = "String";
char s2[] = "STRING";
int flag = 0;
int i, res;
if ( strlen(s1) == strlen(s2) )
{
for ( i = 0; i < strlen(s1); i++ )
{
if ( !no_case_comp(s1[i], s2[i]) )
{
flag = 1;
break;
}
}
if ( flag )
puts("Strings are not equal");
else
puts("Strings are equal");
}
else
puts("Strings are not equal");
return 0;
}
OUTPUT :
// Strings are equal