/*------------------------------------------------------------------------
Section :G/7
M/c No.:32, Roll No.:11BT30015
Name :M A KRISHNA DEEPAK
Assignment No.: 08
Description: Program to implement functions on string characters.
------------------------------------------------------------------------*/
#include <stdio.h>
#define MAXLEN (1000+1)
int strLength(const char *x);
void strReverse(char *x);
int makeUpper(char *x);
char *strCopy(char *x, const char *y);
int isPrefix(const char *x, const char *y);
char *substring(char *x, const char *y);
int main()
{
int len ;
char x[MAXLEN], y[MAXLEN], z[MAXLEN], *cP;
printf("Enter the 1st string:\n") ;
scanf("%[^\n]", x) ;
printf("Enter the 2nd string:\n") ;
scanf(" %[^\n]", y) ;
printf("Length("%s") = %d\n",
x, len = strLength(x));
printf("Reverse("%s") = ", x);
strReverse(x) ;
printf(""%s"\n", x);
strReverse(x) ;
makeUpper(x);
printf("Upper-case: "%s"\n", x);
if(isPrefix(x, y))
printf(""%s" is a prefix of "%s"\n", y, x) ;
else
printf(""%s" is not a prefix of "%s"\n", y, x) ;
/*if((cP = substring(x, y)) == NULL)
printf(""%s" is not a substring of "%s"\n", y, x) ;
else {
printf(""%s" is a substring of "%s"", y, x) ;
printf(" from index %d\n", (int)(cP-x)) ;
}
*/
printf("z[] = "%s"\n", strCopy(z,x)) ;
return 0;
}
int strLength(const char *x)
{
static int sum=0;
int temp;
if(*x=='\0')
{
temp=sum;
sum=0;
return temp;
}
else
{
sum++;
return strLength(x=x+1);
}
}
void strReverse(char *x)
{
int length,c;
char *begin,*end,temp;
length=strLength(x);
begin=x;
end=x;
for(c=0;c<(length-1);c++)
end++;
for(c=0;c<length/2;c++)
{
temp=*end;
*end=*begin;
*begin=temp;
begin++;
end--;
}
}
int makeUpper(char *x)
{
static int u=0;
int temp;
if(*x=='\0')
{
temp=u;
u=0;
return temp;
}
else
{
if(*x>='a' && *x<='z')
{
*x-=32;
u++;
}
return makeUpper(x=x+1);
}
}
char *strCopy(char *x, const char *y)
{
char *p=x;
while(*y)
{
*x =*y;
y++;
x++;
}
*x ='\0';
return p;
}
int isPrefix(const char *x, const char *y)
{
static int l=strLength(y),p=0;
if(*y!=*x *y!='\0')
return 0;
if(*y==*x)
{
p+=isPrefix(x=x+1,y=y+1);
}
if(i==strLength(y))
return 1;
}
/*char *substring(char *x, const char *y)
{
}
*/
Copyright © 2026 eLLeNow.com All Rights Reserved.