- #1
smilesofmiles
- 19
- 0
Hello, I'm extremely new to C++ and will appreciate any help you would be willing to offer. I need to create a function that will find the duplicate characters in a string and then when a duplicate is found, it will break out of the search loop and print the position of the character that was a duplicate.
For example, if the user inputted "Coconuts" the program would print 3 because c has a duplicate at position 3. It wouldn't print any other duplicates because 3 the character c found it's duplicate before any other character did.
My main two questions are:
1. How do I correctly store the length of a user defined array inside of an integer?
2. Should I be using pointers?
Please let me know if I've broken any forum rules or if I need to be more clear, also if there are any problems with my logic. :-( It probably looks like a logical disaster.
Here's what I have so far:
Thank you in advance!
For example, if the user inputted "Coconuts" the program would print 3 because c has a duplicate at position 3. It wouldn't print any other duplicates because 3 the character c found it's duplicate before any other character did.
My main two questions are:
1. How do I correctly store the length of a user defined array inside of an integer?
2. Should I be using pointers?
Please let me know if I've broken any forum rules or if I need to be more clear, also if there are any problems with my logic. :-( It probably looks like a logical disaster.
Here's what I have so far:
Code:
#include <iostream>
#include <array>
#include <string>
using namespace std;
int main(){
char strarr[2000]; // I made this a large number in case the user enters a huge string.
int i = 0;
int j = 0;
int len = strlen(strarr); // I'm trying to store the length of the character array inside of the integer variable len.
cout << "Please enter a string." << endl;
cin.getline(strarr, 2000);
void findDuplicate(char strarr){
while (strarr != '\0'){
for (i = 0, i < len, i++){
for (j = 0, j < len, j++){
if (j = i){
cout << strarr[i];
}
else
cout << "No duplicate indexes found";
}
}
}
return 0; }
Thank you in advance!