Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

//**************************************

//     

//INCLUDE files for :str_functions

//**************************************

//     

only header file  needs to be included

 

code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//     

#include 

int string_length(char string1[40]);

void string_copy(char s1[40],char s2[40]);

int string_compare(char s1[40],char s2[40]);

void string_concat(char sone[40],char stwo[40]);

void main(void)

    {

     char string1[40],s1[40],s2[40];

     int no = 1;

     printf("Enter a word: ");

     gets(string1);

    

     printf("This string %s has %d characters\n\n",string1,string_length(string1));

     printf("-------------------------------------\n\n");

     /*Enter two strings*/

     printf("Enter word (one): ");

     gets(s1);

     printf("\nEnter word (two): ");

     gets(s2);

     printf("\n");

    

     if((string_compare(s1,s2)) == 0)

     printf("\nThese strings are equal\n\n");

     else

     printf("\nThe strings are not equal\n\n");

    

     string_concat(s1,s2);

     string_copy(s1,s2);

     return;

}

/*finds length of string (strlen)*/

string_length(char string2[40])

    {

     int x = 0;

    

     /*if string is not at end of string add 1 to length*/

     while(string2[x] != '\0')

     x++;

     return x;

}/*end of string_length function*/

/*copies string2 to string1 (strcpy)*/

void string_copy(char sone[40],char stwo[40])

    {

     int x,len;

     len = string_length(stwo);

     /*copy each letter from string2 to string1 including 

      null char of string2 (x <= len)*/

     for(x = 0;x <= len;x++)

     sone[x] = stwo[x];

     printf("Now word(two) has been copied to word(one)\n");

     printf("so word(one) is %s \nand word(two) is %s\n\n",sone,stwo);

     return;

}

void string_concat(char sone[40],char stwo[40])

    {

     int i=0,j=0,x,len1,len2;

    

     len1 = string_length(sone);

     len2 = string_length(stwo);

     x = len1;

     /*adding to string1 from null character with string2 (sone[x])

      x is the length of string1 which is the point of the string's 

      null character*/

         for(i = 0;i <= len2;i++){

         sone[x] = stwo[i];

         x++;

         }

         printf("\nThe concatenation of strings is %s\n\n",sone);

    }

    

    /*compares two strings if they are equal in value and case (strcmp)*/

    int string_compare(char sone[40],char stwo[40])

        {

         int x,len1,len2,ret;

         len1 = string_length(sone);

         len2 = string_length(stwo);

         if(len1 != len2)

         printf("\nThe strings are not equal in length\n");

             else{

            

                 for(x=0;x < len1;x++){

                     if(sone[x] != stwo[x]){

                      ret = 1;

                      break;/*break causes program to jump out of for loop*/

                     }/*end if*/

                     }/*end for*/

                     if((x == len2) && (sone[x-1] == stwo[x-1]))

                     ret = 0;

                    

                     }/*end else*/

                     return ret;

                }

 

 

Other 5 submission(s) by this author