0% found this document useful (0 votes)
22 views4 pages

C String Operations in C Programming

Uploaded by

akshayaarb24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

C String Operations in C Programming

Uploaded by

akshayaarb24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CODE:

#include <stdio.h>

int stringLength(char str[])

int len = 0;

while (str[len] != '\0')

len++;

return len;

void stringCopy(char dest[], char src[])

int i = 0;

while (src[i] != '\0')

dest[i] = src[i];

i++;

dest[i] = '\0';

void stringConcat(char str1[], char str2[])

int i = stringLength(str1);

int j = 0;

while (str2[j] != '\0')

str1[i] = str2[j];

i++;

j++;

str1[i] = '\0';

}
int stringCompare(char str1[], char str2[])

int i = 0;

while (str1[i] != '\0' && str2[i] != '\0')

if (str1[i] != str2[i])

return str1[i] - str2[i];

i++;

return str1[i] - str2[i];

void stringReverse(char str[])

int start = 0;

int end = stringLength(str) - 1;

char temp;

while (start < end)

temp = str[start];

str[start] = str[end];

str[end] = temp;

start++;

end--;

int main()

char str1[100], str2[100], copy[100];

printf("\t\t\tPROGRAM 3:STRING OPERATION\n");

printf("\t\t\t**************************\n");

printf("Enter first string: ");


gets(str1);

printf("Enter second string: ");

gets(str2);

printf("\nLength of first string: %d\n", stringLength(str1));

stringCopy(copy, str1);

printf("Copied string: %s\n", copy);

stringConcat(str1, str2);

printf("Concatenated string: %s\n", str1);

int cmp = stringCompare(copy, str2);

if (cmp == 0)

printf("Strings are equal\n");

else if (cmp > 0)

printf("First string is greater\n");

else

printf("Second string is greater\n");

stringReverse(copy);

printf("Reversed first string: %s\n", copy);

return 0;

OUTPUT:

PROGRAM 3:STRING OPERATION

**************************

Enter first string: she is clever

Enter second string: the team has good coordination

Length of first string: 13

Copied string: she is clever

Concatenated string: she is cleverthe team has good coordination

Second string is greater

Reversed first string: revelc si ehs


OUTPUT:

PROGRAM 3:STRING OPERATION

**************************

Enter first string: same

Enter second string: same

Length of first string: 4

Copied string: same

Concatenated string: samesame

Strings are equal

Reversed first string: emas

OUTPUT:

PROGRAM 3:STRING OPERATION

**************************

Enter first string: sunday is funday

Enter second string: bye see you

Length of first string: 16

Copied string: sunday is funday

Concatenated string: sunday is fundaybye see you

First string is greater

Reversed first string: yadnuf si yadnus

You might also like