I'm having a problem with a program. The program should make an char array with max 80 chars, then the user should input something (for example, user inputs: abacdce) and then the program should make another char array that contains every char from first char array that is not repeating itself. So if user inputted : abacdce then the program should give out : bde. Because 'b' and 'd' and 'e' are not repeating itselfs in the first char array.
This is my code. It just gives an error. What seems to be a problem ?
#include <iostream>
using namespace std;
int main()
{
char a[80];
char b[80];
int n, m, anzahl = 0;
You code is far more complex than it has to be. All you need to do is;
1: Declare an array of 26 int's
2: Declare a string
3 Iterate through each character, testing if it's alpha, if so converting to uppercase and then subtracting 41 from it. That leaves you with an index and you can increment your array by one for each occurrence.
After all is done each position will be either;
0 if that character wasn't used
1 if it was only used once
>1 in all other cases.
I'm going to give you a big boost here, as you did put in a reasonable attempt.
#include <iostream>
#include <string>
usingnamespace std;
int main() {
int Used [26] = {0};
string Entry;
getline ( cin, Entry, '\n' );
if ( !Entry.empty () ) {
for ( auto ch : Entry ) {
// Your code here
}
}
// Your code to do whatever type of display you want.
return 0;
}
I've got a completed version of the program and this is the output from your example.
2 A
1 B [B]
2 C
1 D [D]
1 E [E]
0 F
0 G
0 H
0 I
0 J
0 K
0 L
0 M
0 N
0 O
0 P
0 Q
0 R
0 S
0 T
0 U
0 V
0 W
0 X
0 Y
0 Z