Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 21-08-2010, 10:51 PM   #1 (permalink)
Designer Here
 
techking_dinesh's Avatar
 
Join Date: Aug 2008
Location: Nashik
Posts: 396
Default [C] Help with Strings


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

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
techking_dinesh is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 22-08-2010, 10:15 PM   #2 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Help with Strings in C

in ur case pointer function is of no use:

Code:
void fun1(char a[]) == void fun1(char *a)
u must return value for string compare
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 23-08-2010, 08:29 AM   #3 (permalink)
Designer Here
 
techking_dinesh's Avatar
 
Join Date: Aug 2008
Location: Nashik
Posts: 396
Default Re: Help with Strings in C

Well we are learning C.. Our Assignment is

Menu
1. Without Pointer
2. With Pointer

On pressing 1, d string menu appears where everything is calculated without pointers
& on 2 , d same menu appears bt the calculations are done with pointers

Use of library functions is not allowed
techking_dinesh is offline   Reply With Quote
Old 23-08-2010, 10:34 AM   #4 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Help with Strings in C

u need to know what r pointers... seriously!

study the pages as given in the series from 1 to 4 (a bit of an overload but necessary)

1.Everything you need to know about pointers in C
2.Arrays and Pointers
3.http://www.eskimo.com/~scs/cclass/int/sx5.html
4.Returning an array from a fuction - C and C++ - Forums at ProgrammersHeaven.com
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Old 27-08-2010, 08:15 PM   #5 (permalink)
Designer Here
 
techking_dinesh's Avatar
 
Join Date: Aug 2008
Location: Nashik
Posts: 396
Default Re: Help with Strings in C

thank a lot.. i ll go through them
techking_dinesh is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quantum teleportation achieved over 16 km celldweller1591 Technology News 19 24-05-2010 05:24 PM
Google Search ! ! ! ax3 Internet & WWW 14 29-04-2009 07:37 AM
VISTA TUTORIAL: Add Customized Strings in System Properties Dialog Box Vishal Gupta Tutorials 7 11-07-2007 10:16 PM
Top 10 Tips for Linux Users - O'Reilly's Gigacore Open Source 1 04-06-2007 10:17 AM
Quake 4 ..starting error.. medigit Gamerz 4 14-04-2007 06:56 PM

 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:21 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2