String Program
String Program
Q2. program to check whether a string is palindrome without using string function
#include <stdio.h>
#include <string.h>
int main()
{
char text[20], reverse_text[20];
int i,n, length = 0;
return 0;
}
Q3. program to check whether a string is palindrome or not using string function
#include <stdio.h>
#include <string.h>
void main()
{
char string[50], string_reverse[50];
getch();
}
s2[i] = '\0';
printf("String s2: %s", s2);
return 0;
}
Q5. Count the total number of words in a string
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define str_size 100 //Declare the maximum size of the string
void main()
{
char str[str_size];
int i, wrd;
printf("\n\nCount the total number of words in a string :\n");
printf("------------------------------------------------------\n");
printf("Input the string : ");
gets(str);
i = 0;
wrd = 1;
i++;
}
Q6. Write a program in C to compare two string without using string library functions
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char str1[str_size], str2[str_size];
int flg=0;
printf("\n\nCompare two string whether they are equal or not :\n");
printf("------------------------------------------------------\n");
printf("Input the 1st string : ");
gets(str1);
printf("Input the 2nd string : ");
gets(str2);
int i=0;
if(flg == 0)
{
printf("\nThe length of both strings are equal and \nalso both strings are
equal.\n\n");
}
else if(flg == -1)
{
printf("\nThe length of the first string is smaller than second.\n\n");
}
else
{
printf("\nThe length of the first string is greater than second.\n\n");
}
getch();
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
char str1[100], str2[100];
int i;
printf("\n\nCopy one string into another string :\n");
printf("-----------------------------------------\n");
printf("Input the string : ");
gets(str1);
void main()
{
char Str[100], RevStr[100];
int i, j, len;
printf("\n Please Enter any String : ");
gets(Str);
j = 0;
len = strlen(Str);
for (i = len - 1; i >= 0; i--)
{
RevStr[j++] = Str[i];
}
RevStr[i] = '\0';
printf("\n String after Reversing = %s", RevStr);
getch();
}