creating our own C++ strcat() function, code reqd

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

creating our own C++ strcat() function, code reqd

 
0
  #1
Nov 20th, 2005
hello everyone
i was trying to make my own own string concatenation function but wasnt able to do so. i need ur help.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: creating our own C++ strcat() function, code reqd

 
0
  #2
Nov 20th, 2005
Originally Posted by sahil_logic
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?
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: creating our own C++ strcat() function, code reqd

 
0
  #3
Nov 20th, 2005
Originally Posted by Rashakil Fol
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
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. char m,str1[50],str2[50],str3[100];
  5.  
  6. int main()
  7. {
  8.  
  9. int l=0;
  10. gets(str1);
  11. gets(str2);
  12. for(int i=0;str1[i]!='/0';i++)
  13. {str3[i]=str1[i];
  14. l=l+1;}
  15. for(int j=0;str2[j]=!'/0';j++)
  16. str3[l+j]=str2[j];
  17.  
  18. str3[i+j]='/0';
  19. cout<<" the concatinated str is "<<puts(str3);
  20. getch();
  21. return 0;
  22. }
plz debug it
Last edited by Dave Sinkula; Nov 20th, 2005 at 3:27 pm. Reason: Added [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: creating our own C++ strcat() function, code reqd

 
0
  #4
Nov 20th, 2005
It should be
  1. str2[j]!='\0'
not
  1. str2[j]=!'/0'
change '/0' in first for loop also...use fgets instead of gets
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: creating our own C++ strcat() function, code reqd

 
0
  #5
Nov 20th, 2005
Originally Posted by sunnypalsingh
It should be
  1. str2[j]!='\0'
not
  1. 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: creating our own C++ strcat() function, code reqd

 
0
  #6
Nov 20th, 2005
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
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. char m,str1[50],str2[50],str3[100];
  5.  
  6. int main()
  7. {
  8.  
  9. int i,j,temp,l=0;
  10. gets(str1);
  11. gets(str2);
  12.  
  13. for(i=0;str1[i]!='\0';i++)
  14. {
  15. str3[i]=str1[i];
  16. l=l+1;
  17. }
  18. for(j=0;str2[j]!='\0';j++)
  19. str3[l+j]=str2[j];
  20.  
  21. str3[i+j]='\0';
  22. cout<<" the concatinated str is "<<puts(str3);
  23. getch();
  24. return 0;
  25. }

Next Time Use this to stop the output window in DEV instead of getch() which requires <conio.h>
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. // Your code here
  9.  
  10. // Clean up the stream and ask for input
  11. cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
  12. cin.get();
  13. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: creating our own C++ strcat() function, code reqd

 
0
  #7
Nov 20th, 2005
[/code][/QUOTE]
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: creating our own C++ strcat() function, code reqd

 
0
  #8
Nov 20th, 2005
plz debug this prog to make a matrix
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. int main()
  5. {
  6. int ar[3][4];
  7. for(int i=0;i<3;i++)
  8. {
  9. for(int j=0;j<4;j++)
  10. {
  11. cin>>ar[i][j];
  12.  
  13. }
  14. }
  15.  
  16. for(int k=0;k<3;k++)
  17. {
  18. for(int p=0;p<4;p++)
  19. {
  20. cout<<ar[i][j]<<"/t";
  21.  
  22. }
  23. }
  24. return 0;
  25. }
Last edited by Dave Sinkula; Nov 20th, 2005 at 3:27 pm. Reason: Added [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

Re: creating our own C++ strcat() function, code reqd

 
0
  #9
Nov 20th, 2005
plz find the error n correct it
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. int main()
  5. {
  6. char str[20],l=0,flag=1;
  7. cout<<"enter the string " ;
  8. gets(str);
  9. for(int i=0;str[i]!='/0';i++)
  10. l++;
  11. for(int j=0;j<=(l-1)/2;j++)
  12. {
  13.  
  14. if(str[j]==str[l-1])
  15. flag=1;
  16. else break;
  17. }
  18. if(flag==1)
  19. cout<<" string is a palindrome ";
  20. else cout<< " string is not a palindrome ";
  21. getch();
  22.  
  23. }
//palindromes = nitin,malayalam ,madam etc
Last edited by Dave Sinkula; Nov 20th, 2005 at 3:28 pm. Reason: Added [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: creating our own C++ strcat() function, code reqd

 
0
  #10
Nov 20th, 2005
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC