hello everyone
i was trying to make my own own string concatenation function but wasnt able to do so. i need ur help.

hello everyone
i was trying to make my own own string concatenation function but wasnt able to do so. i need ur help.

What don't you understand that prevents you from doing this? What do you think would be a subroutine that does work?

What don't you understand that prevents you from doing this? What do you think would be a subroutine that does work?

by this time i converted it to a prog

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
char m,str1[50],str2[50],str3[100];

int main()
{
    
    int l=0;
    gets(str1);
    gets(str2);
    for(int i=0;str1[i]!='/0';i++)
    {str3[i]=str1[i];
    l=l+1;}
    for(int j=0;str2[j]=!'/0';j++)
    str3[l+j]=str2[j];
    
    str3[i+j]='/0';
    cout<<" the concatinated str is "<<puts(str3);
    getch();
    return 0;
}

plz debug it

It should be

str2[j]!='\0'

not

str2[j]=!'/0'

change '/0' in first for loop also...use fgets instead of gets

It should be

str2[j]!='\0'

not

str2[j]=!'/0'

change '/0' in first for loop also...use fgets instead of gets

well sunny i did wat u said
but m still getting errors n warning . here they are --
Compiler: Default compiler
Executing
In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,
from C:\Dev-Cpp\concatination.cpp:1:
C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
C:\Dev-Cpp\concatination.cpp: In function `int main()':
C:\Dev-Cpp\concatination.cpp:18: error: name lookup of `i' changed for new ISO `for' scoping
C:\Dev-Cpp\concatination.cpp:12: error: using obsolete binding at `i'

C:\Dev-Cpp\concatination.cpp:18: error: name lookup of `j' changed for new ISO `for' scoping
C:\Dev-Cpp\concatination.cpp:15: error: using obsolete binding at `j'

Execution terminated

Here's the corrected code....stop mixing c headers with c++ headers....don't use ancient headers like <iostream.h>...instead use <iostream>.....declare variable outside for loop...not allowed according to latest ISO standard

#include<iostream>
#include<conio.h>
using namespace std;
char m,str1[50],str2[50],str3[100];

int main()
{

int i,j,temp,l=0;
gets(str1);
gets(str2);

for(i=0;str1[i]!='\0';i++)
{
        str3[i]=str1[i];
        l=l+1;
}
for(j=0;str2[j]!='\0';j++)
        str3[l+j]=str2[j];

str3[i+j]='\0';
cout<<" the concatinated str is "<<puts(str3);
getch();
return 0;
}

Next Time Use this to stop the output window in DEV instead of getch() which requires <conio.h>

#include <iostream>
#include <limits>

using namespace std;

int main()
{
  // Your code here

  // Clean up the stream and ask for input
  cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
  cin.get();
}

m getting thisas output n not wat i want , also can u now convert it to a function like strcat()
as
fg
asfg
the concatinated str is 0

plz debug this prog to make a matrix

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
    int ar[3][4];
    for(int i=0;i<3;i++)
    {
       for(int j=0;j<4;j++)
       {
          cin>>ar[i][j];
          
       }
    }
    
    for(int k=0;k<3;k++)
      {
            for(int p=0;p<4;p++)
            {
                    cout<<ar[i][j]<<"/t";
                    
            }
      }
return 0;
}

plz find the error n correct it

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
    char str[20],l=0,flag=1;
    cout<<"enter the string " ;
    gets(str);
    for(int i=0;str[i]!='/0';i++)
    l++;
    for(int j=0;j<=(l-1)/2;j++)
    {
            
            if(str[j]==str[l-1])
            flag=1;
            else break;                        
    }
     if(flag==1)
     cout<<" string is a palindrome ";
     else cout<< " string is not a palindrome ";
     getch();
     
}

//palindromes = nitin,malayalam ,madam etc

whatever code u have written in main...write it in another function and call that function by passing the indivisual strings and return the concatenated string from it...
Try searching a bit before asking....u'll find it in this forum itself

dont debug that matrix one . did it myself

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
    int ar[3][4];
    for(int i=0;i<3;i++)
    {
       for(int j=0;j<4;j++)
       {
          cin>>ar[i][j];
          
       }
    }
    cout<<endl;
    for(int k=0;k<3;k++)
      {
            for(int p=0;p<4;p++)
            {
                    cout<<ar[k][p]<<"\t";
                    
            }
            cout<<endl;
      }
getch();
return 0;
}

As for the strcat, this is in the Code Snippets:
Strings: Concatenation

[edit]And never use gets.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.