Hello All.
I am currently working on a project that introduces us to recursion and was needing some help with my program. This is early code so i know many things aren't correct.
#include <iostream>
#include <fstream>
using namespace std;
int str_length(const char[] str);
int str_compare(const char[] str1, const char[] str2);
void str_reverse(char[] str, int length);
bool str_replace_first(char[] str, const char[] find, const char[] replace, bool is_partial_match);
int main (int argc, char* argv[])
{
ifstream infile;
infile.open (argv[1]);
ofstream outfile;
outfile.open (argv[2]);
if (argc < 3)//checks parameters on the command line
{
cout << "Error: usage:main input output" << endl;
return 1;
}
char a[50];
for (int i=0; i<50; i++)
{
a[i] = 'A' + i;
a[49] = '\0';
cout << "string before reversing: " << a << endl;
stringReverse( a );
cout << "string after reversing: " << a << endl;
return 0;
}
//max length on list
const int LINE_LENGTH = 100;
//data type of list items
char str[LINE_LENGTH];
//checks to see if characters are readable
while( infile.getline(str, LINE_LENGTH))
{
cout << "Read from file: " << str << endl;
}
//make sure to close your file.
infile.close();
}
//Writes a string of characters backwards
//pre: There must be characters. Size is >= 0
int str_length(const char[], int str)
int str_compare(const char[], int str1, const char[], int str2)
void str_reverse(char[], int str, int length)
{
if (length > 0)
{
cout << str.substr(length-1, 1);
str_reverse(str, length-1);
}
}
bool str_replace_first(char[] str, const char[] find, const char[] replace, bool is_partial_match)
i am currently working on the str_length function. I m not sure where to start. My two biggest problems is that i am unsure how to run this function when it is called in the terminal and second, i am unsure to to get the data that is being stored in the array for the input file then print that count to the output file. Also, we were given sample input and out on the user level of the program as a means to test our code. I will list that below. Thanks for all the help.
Sample Input
reverse hello
length_iter basketball
compare Duck elephant
replace_first there re ir
Sample Output
olleh
10
-33
their