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
sprintf
(see:
http://www.rohitab.com/discuss/topic/11505-sprintf-tutorial-in-c/[
^]).
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.
[Update]
Ok, so it is an RLE, even not the finest one. But see this solution, with some comment. If C, make it C.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
char *doArchive(char *str, char *dest)
{
char tmp[10];
int idx_from;
if(!str || !dest || !str[0]) 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;
}
while(str[idx_from]);
return dest;
}
void main()
{
char str[N];
char dest[N*2];
printf("Enter your string: ");
gets(str);
printf("Result: %s", doArchive(str,dest));
}