0% found this document useful (0 votes)
2 views3 pages

String Program

The document contains C code examples demonstrating string manipulation functions without using standard library functions. It includes implementations for calculating string length, copying strings, concatenating strings, and comparing strings. Each example prompts the user for input and displays the result accordingly.

Uploaded by

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

String Program

The document contains C code examples demonstrating string manipulation functions without using standard library functions. It includes implementations for calculating string length, copying strings, concatenating strings, and comparing strings. Each example prompts the user for input and displays the result accordingly.

Uploaded by

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

String Length Without strlen()

#include <stdio.h>
int main()
{
char str[100];
int i = 0;
printf("Enter a string: ");
scanf("%s", str);
while(str[i] != '\0')
{
i++;
}
printf("Length = %d", i);
return 0;
}

Output

Enter a string: Hello


Length = 5

String Copy Without strcpy()

#include <stdio.h>
int main()
{
char str1[100], str2[100];
int i = 0;
printf("Enter string: ");
scanf("%s", str1);
while(str1[i] != '\0')
{
str2[i] = str1[i];
i++;
}
str2[i] = '\0';
printf("Copied string = %s", str2);
return 0;
}

Output
Enter string: Apple
Copied string = Apple

String Concatenation Without strcat()

#include <stdio.h>
int main()
{
char str1[100], str2[100];
int i = 0, j = 0;
printf("Enter first string: ");
scanf("%s", str1);
printf("Enter second string: ");
scanf("%s", str2);
while(str1[i] != '\0')
{
i++;
}
while(str2[j] != '\0')
{
str1[i] = str2[j];
i++;
j++;
}

str1[i] = '\0';

printf("Concatenated string = %s", str1);


return 0;
}

Enter first string: Good


Enter second string: Morning
Concatenated string = GoodMorning

String Compare Without strcmp()

#include <stdio.h>

int main()
{
char str1[100], str2[100];
int i = 0, flag = 0;
printf("Enter first string: ");
scanf("%s", str1);
printf("Enter second string: ");
scanf("%s", str2);
while(str1[i] != '\0' || str2[i] != '\0')
{
if(str1[i] != str2[i])
{
flag = 1;
break;
}
i++;
}
if(flag == 0)
printf("Strings are equal");
else
printf("Strings are not equal");
return 0;
}

Output

Enter first string: Hello


Enter second string: Hello
Strings are equal

You might also like