944,100 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 12845
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 20th, 2005
0

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

Expand Post »
hello everyone
i was trying to make my own own string concatenation function but wasnt able to do so. i need ur help.
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Nov 20th, 2005
3

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

Quote 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?
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Nov 20th, 2005
0

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

Quote 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
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Nov 20th, 2005
0

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

It should be
C++ Syntax (Toggle Plain Text)
  1. str2[j]!='\0'
not
C++ Syntax (Toggle Plain Text)
  1. str2[j]=!'/0'
change '/0' in first for loop also...use fgets instead of gets
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Nov 20th, 2005
0

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

Quote originally posted by sunnypalsingh ...
It should be
C++ Syntax (Toggle Plain Text)
  1. str2[j]!='\0'
not
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Nov 20th, 2005
0

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

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
C++ Syntax (Toggle Plain Text)
  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>
C++ Syntax (Toggle Plain Text)
  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. }
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Nov 20th, 2005
0

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

[/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
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Nov 20th, 2005
0

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

plz debug this prog to make a matrix
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Nov 20th, 2005
0

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

plz find the error n correct it
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Nov 20th, 2005
0

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

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
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ Slot machine
Next Thread in C++ Forum Timeline: help with square root finder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC