Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how can i modify the code so that the output will be just one copy of the repate

ID: 3639893 • Letter: H

Question

how can i modify the code so that the output will be just one copy of the repated charecters only

for example: for this string str[] = "abbbbccdffk";, the output should be just "bcf";


#include<stdio.h>
#include <sting.h>
int main()
{
char str[] = "abbbbccdffk";
int len = strlen(str);
int read_pos, write_pos, prev_char;

prev_char = str[0] + 1;
for (read_pos = 0, write_pos = 0; read_pos < len; read_pos++)
{
if (str[read_pos] != prev_char)
{
str[write_pos] = str[read_pos];
write_pos++;
}
prev_char = str[read_pos];
}
str[write_pos] = '';

printf("str = %s ", str);
return 0;
}

Explanation / Answer

#include #include int main() { char str[] = "abbbbccdffk"; int len = strlen(str); int read_pos, write_pos,next_pos, prev_char; prev_char = str[0]+1; printf("%c ",prev_char); for (read_pos = 0, write_pos = 0; read_pos