| | |
creating our own C++ strcat() function, code reqd
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
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.
All my posts may be redistributed under the GNU Free Documentation License.
•
•
Join Date: Nov 2005
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
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?
C++ Syntax (Toggle Plain Text)
#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; }
Last edited by Dave Sinkula; Nov 20th, 2005 at 3:27 pm. Reason: Added [code][/code] tags.
It should be not change '/0' in first for loop also...use fgets instead of gets
C++ Syntax (Toggle Plain Text)
str2[j]!='\0'
C++ Syntax (Toggle Plain Text)
str2[j]=!'/0'
•
•
Join Date: Nov 2005
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by sunnypalsingh
It should benotC++ Syntax (Toggle Plain Text)
str2[j]!='\0'change '/0' in first for loop also...use fgets instead of getsC++ Syntax (Toggle Plain Text)
str2[j]=!'/0'
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
Next Time Use this to stop the output window in DEV instead of getch() which requires <conio.h>
C++ Syntax (Toggle Plain Text)
#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>
C++ Syntax (Toggle Plain Text)
#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(); }
•
•
Join Date: Nov 2005
Posts: 31
Reputation:
Solved Threads: 0
plz debug this prog to make a matrix
C++ Syntax (Toggle Plain Text)
#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; }
Last edited by Dave Sinkula; Nov 20th, 2005 at 3:27 pm. Reason: Added [code][/code] tags.
•
•
Join Date: Nov 2005
Posts: 31
Reputation:
Solved Threads: 0
plz find the error n correct it
//palindromes = nitin,malayalam ,madam etc
C++ Syntax (Toggle Plain Text)
#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(); }
Last edited by Dave Sinkula; Nov 20th, 2005 at 3:28 pm. Reason: Added [code][/code] tags.
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ Slot machine
- Next Thread: help with square root finder
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






