Your question and your code gave me different ideas about what you probably want
A) If you want to "print" to a string instead of the standard output, use
B) In your case dest array can be only used to store the count, but I would use int * instead of char *. But you can not print it directly. You will need a loop print the counts as numbers from within that loop.
But we don't do homework, we don't have the specification of it - thus go on, and try to figure out, what you missed.
Ok, so it is an RLE, even not the finest one. But see this solution, with some comment. If C, make it C.
#define N 100
char *doArchive(char *str, char *dest)
char tmp; int idx_from;
if(!str || !dest || !str) return NULL;
*dest = 0; idx_from = 0; do
int idx_to = idx_from + 1; while(str[idx_to] && str[idx_from] == str[idx_to]) idx_to++;
sprintf(tmp, "%c%d", str[idx_from], idx_to-idx_from); strcat(dest, tmp);
idx_from = idx_to; }
char str[N]; char dest[N*2]; printf("Enter your string: ");
printf("Result: %s", doArchive(str,dest));