answersLogoWhite

0

/*------------------------------------------------------------------------

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)

{

}

*/

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How did the South use the raw materials change after the war?

Raw materials were used by new southern Industries


How did the south use raw materials change after the war?

Raw materials were used by new southern Industries


How did the south's use raw materials change after the war?

Raw materials were used by new southern Industries


How did the souths use of raw materials change after the war?

Raw materials were used by new southern industries.


What are the raw material used by agro based industries?

Beverages used raw materials are cocoa


What type of economy is based on mining or producing raw materials to used in foreign industries?

An industrial economy is based on mining or producing raw materials to be used in foreign industries.


What type of economy is based in mining or producing raw materials to be used in foreign industries?

An industrial economy is based on mining or producing raw materials to be used in foreign industries.


What type of economy is based on mining or producing raw materials to be used to foreign industries?

An industrial economy is based on mining or producing raw materials to be used in foreign industries.


What type of economy is based on mining or producing raw materials to be used in foreign industries?

An industrial economy is based on mining or producing raw materials to be used in foreign industries.


How did the use of raw material change after the war?

Raw materials were used by new southern industries.


What are the raw materials used in jute industries?

Raw Jute is most important raw material for the jute industry


''agriculture and industry are complementary to each other'' justify the statement?

most of the raw materials used in industries are agricultural raw materials......... the industries manufacture pesticides,fertilizers, etc which are used in agricultural activities