HELP WITH CODE IN C, STRINGS

Asked

Viewed 37 times

-1

// what changes I have to make to make each character repeat once more than the previous one?

for example: input: Roberto exit: Roobbbeeeerrrttttooooooooooo

#include <stdio. h> #include <string. h>

void main (){ char string[50]; int num, Eng;

printf("String inicial: ");
scanf("%s,", string);
printf("Numero: ");
scanf("%d", &num);

leng = strlen(string);
char  stringFinal[leng*num];

printf("String final: ");
for (int i = 0; i < leng; i++){
    for (int j = 0; j < num; j++){
        printf("%c ", string[i]);
    }
}
printf("\n");

}

GRATEFUL

1 answer

0

Using the string definition in C, a possible solution is:

#include <stdio.h>
void main (){
    char string[50];
    printf("String inicial: ");
    scanf("%s", string);
    printf("String final: ");
    for (int i = 0; string[i] != '\0'; i++) {
        for (int j=0; j<i+1; j++) {
            printf("%c", string[i]);
        }
    }
    printf("\n");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.