Answer the question
In order to leave comments, you need to log in
Why doesn't it display d values correctly?
#include <stdio.h>
#pragma warning(disable : 4996)
int main() {
unsigned char a[81], perm[256], g[81], d = 0, n = 0;
for (int f = 0; f < 81; f++) {
scanf("%[^\n]d", &a);
}
int f = 0;
while (a[f] != '\0') {
n++; f++;
}
for (int b = 0; b < 256; b++) {
perm[b] = b;
for (int c = 0; c < n; c++) {
if (a[c] == perm[b]) {
g[c] = perm[b];
}
}
}
for (int c = 0; c < n; c++) {
if (g[c] == g[c + 1]) {
d++;
}
else d = 1;
//printf(" %d ", g[c]);
printf(" %c=%d\n ", g[c], d);
}
}
Answer the question
In order to leave comments, you need to log in
Are you seriously suggesting that we understand what goes wrong in an algorithm that has no input and no description? And even with unreadable code?
Not a single comment.
Who will be interested in understanding this mess? The debugger is in the teeth - and trace the program step by step, tracking the counters.
Apparently it needs to
for (int c = 0; c < n; c++) {
if (g[c] == g[c + 1]) {
d++;
continue;
}
else d = 1;
//printf(" %d ", g[c]);
printf(" %c=%d\n ", g[c], d);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question