Hello C++/C Programmers there,
Please help with my program in C++, my program is always have 2 errors every time I compile and run it. My program is about string permutation which has main menu first. Here is my codes:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int count=0;
void permut(char stra1[],char append[])
{
int length = strlen(stra1);
if (length)
{
for(int i=0;i<length;++i)
{
char* str2 = new char[length+1];
int count1;
int count2;
for(count1=0,count2=0; count1<length; ++count1,++count2)
{
if (count1 == i)
{
str2[count1] = stra1[++count2];
continue;
}
else
str2[count1] = stra1[count2];
}
str2[count1] = '\0';
int alength = strlen(append);
char* append1 = new char [alength+2];
strncpy(append1,append,alength);
append1[alength] = stra1[i];
append1[alength+1] = '\0';
permut(str2,append1);
delete []str2;
delete []append1;
}
}
else
{
count=count+1;
cout << append << endl;
}
}
void main()
{
clrscr();
char choice;
char ans;
do
{
cout<<" Main Menu: \n";
cout<<" A.)String Permutation\n";
cout<<" B.)About\n";
cout<<" B.)Exit\n";
cout<<" Enter your Choice[A,B,C]: ";
gotoxy(60,16);cin>>choice;
if(choice=='A'|| choice=='a')
{
clrscr();
cout<<"Enter a word/string: ";
char stra1[25];
cin>>stra1;
char append[] = "\0";
cout << "\nInput Word/String: "<< stra1;
cout<<"\n\nPermutations: \n\n";
permut(stra1,append);
cout<<"\nPermutation Count: "<<count;
}
if(choice=='B'|| choice=='b')
{
clrscr();
cout<<"A String Permutation Program\n";
}
if(choice=='C'|| choice=='c')
{
clrscr();
cout<<"You choose to terminate the program. Press enter to continue...";
}
cout<<"\n\nTry Again[y/n]: ";
cin>>ans;
clrscr();
}while(ans!='n'); getche();}
Every time I compile and run my program there’s 2 errors which says:
"Function ‘strlen’ should have a prototype" in this line:
int length = strlen(stra1);
"Function ‘strncpy’ should have a prototype" in this line:
strncpy(append1,append,alength);
Please help me with this program, I try my besy but I just cant figure out what is my mistake.. Thank You