/*the program gots a string, and supposed to copy to the destination
string every letter only once, and after a letter a num - a counter how many times a letter appeared in the original string
for example - for kuku it should return k2u2 - but it returns k0u0 - can someone help??? */
#include <stdio.h>
int RLE (char *string, char letter);
void Change(char *source, char *dest);
void main()
{
char str[20];
char enc[20];
printf("enter a string...");
gets_s(str);
Change(str, enc);
printf("%s",enc);
//puts(enc);
}
void Change(char *source, char *dest)
{
char *s;
char *d;
int i;
d=dest;
s=source;
for (i=0;*s;i++,s++)
{
if(RLE (d, s[i])==0) //meaning if in the destination string hasn't already the letter
{
*d=*s; //then add the letter
*(++d)=(RLE(source, s[i]))+'0'; //this one adds how many times the letter appears in the source string
d++;
}
}
*d='\0';
}
int RLE (char *string, char letter) //returns count of letter's appearance in string
{
char *b;
int count=0;
b=string;
while(*b)
{ if(*b==letter)
count++; //why the count stays on 0???
b++;
}
return count;
}
yila -3 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
yila -3 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
yila -3 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.