techking_dinesh
Digit Squad Member
Hello I need to do a menu driven programme on strings
without using the library functions like strcpy and stuff
I need to do the programme in 2 modes..
1.Using functions
2. using pointers
I am almost Done with part I... I am not able to code string compare , Palindrome and Sub String
I am hopeless with 2nd part of pointers
Help me as much as u can
Here is my code
Waiting for proper guidance
without using the library functions like strcpy and stuff
I need to do the programme in 2 modes..
1.Using functions
2. using pointers
I am almost Done with part I... I am not able to code string compare , Palindrome and Sub String
I am hopeless with 2nd part of pointers
Help me as much as u can
Here is my code
Code:
// Assignment 2 Coded By Dinesh Modi
#include<stdio.h>
#include<conio.h>
void create_set(char a[100],int size1);
void print_set(char a[100],int size1);
void copy_set(char a[100],int size1,char c[100]);
void reverse_set(char a[100],int size1,char c[100]);
//void stringcmp(char a[100], char b[100]);
void main()
{
char a[100],b[100],c[100];
int i,size1,size2,j,ch;
clrscr();
do
{
printf("\n\n\n String Operations Menu");
printf("\n 1. Create String");
printf("\n 2. Display String");
printf("\n 3. Copy String");
printf("\n 4. Reverse String");
printf("\n 5. Compare String");
printf("\n 6. Palindrome");
printf("\n 7. Exit");
printf("\n\n Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: // Creation of String
printf("\n\n Enter the size of first string:");
scanf("%d",&size1);
printf("\n\n enter %d characters: ",size1);
create_set(a,size1);
printf("\n\n Enter the size of second string:");
scanf("%d",&size2);
printf("\n\n Enter %d character: ",size2);
create_set(b,size2);
break;
case 2:
printf("\n\n String is: \n");
print_set(a,size1);
printf("\n\n String is: \n");
print_set(b,size2);
break;
case 3: // Copy String
copy_set(a,size1,c);
printf("\n Copied String is : ");
print_set(c,size1);
break;
case 4: // Reverse of String
reverse_set(a,size1,c);
printf("\n Reverse of String is : ");
print_set(c,size1);
break;
case 5: // Comparision of string
if(size1!=size2)
printf("they are different strings");
else
while(a[i]!='\0')
if(a[i]==b[i])
i++;
else
printf("They are different strings");
//exit(0);
printf("Both are same");
break;
default:
printf("\n Enter Proper Choice");
}
}
while(ch<8);
}
// Function Starts Here
// String Creation
void create_set(char a[100],int size1)
{
int i;
for(i=0;i<size1;i++)
{
scanf("%s",&a[i]);
}
}
// String Display
void print_set(char a[100],int size1)
{
int i;
// printf("\n\n String is: \n");
for(i=0;i<size1;i++)
{
printf("%c",a[i]);
}
}
// Copy String Functon
void copy_set(char a[100],int size1,char c[100])
{
int i,j;
for(i=0;i<=size1;i++)
{
j=0;
for(j=0;j<=size1;j++)
{
c[i]=a[i];
j++;
}
}
}
// Reverse String Function
void reverse_set(char a[100],int size1,char c[100])
{
int i,j;
for(i=size1;j=0,i>=0;i--,j++)
{
for(j=0;j>size1;j++)
{
c[i]=a[i];
printf("%c",c[j]);
printf("%c",c[i]);
}
printf("%c",c[j]);
}
}
/* Compare
void stringcmp(char a[100], char b[100])
{
int i,j;
for(i=0;a[i]!='\0';i++)
{
for(j=0;b[j]!='\0';j++)
{
if(a[i] == b[j])
continue;
}
}
if (i==j)
{
printf("String s1:%s and s2:%s are EQUAL\n",a[i],b[j]);
}
else
printf("String s1:%s and s2:%s are NOT EQUAL\n",a[i],b[j]);
}
*/
// Palindrome Logic
/*
char string,string1;
printf("enter the string:\n");
scanf("%s",&string);
strcpy(string1,string);
strrev(string);
if(strcmp(string1,string)==0)
{
printf("string is palendrome");
}
else
{
printf("string is not palendrome");
}
// Pal function
for(i=0;a[i]!=0;i++);
for(j=0;i!=0;i--)
{ b[j++]=a[i];
}
b[j]=0;
for(i=0;a[i]!=0;i++)
{ if(a[i]!=b[i])
{ f=0;
break;
}
}
if(f==0)
printf("NOT PALINDROME");
else
printf("PALINDROME");
*/
Waiting for proper guidance