infile >> a >> c >> d;
requires a char
array and 2 integers all separated by spaces.
flohjenwxhas
contains no spaces so the char array gobbles everything up and the stream read fails untested leaving nothing for c
and d
. This means c
and d
are used without being set later in the program. This be Undefined Behaviour. Crom only knows what crazy smurf will result when they are used.
int l = sizeof(a) / sizeof(a[0]);
Computes the number of element in array a
. Not only is this redundant, it will always be 100, it is far more than the number of characters in “flohjenwxhas”. This has you sorting and swapping who-knows-what in the uninitialized portion of a
.
You likely meant to use
int l = strlen(a);
But a vastly better approach is to make a
a std::string
and use a.size()
1
solved Why is @@@@P` is being added to char array after sorting