Дана строка.Преобразовать ее,удалив каждый символ * и повторив каждый символ,отличный от * Кто сделает всё верно, прилично заплачу, главное чтобы прога была на чистом Си
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, const char * argv[]) { char *str = "sdafsf*fsf**fs"; int count = 0; for (int i = 0; i < strlen(str); i++) { if (str[i] == '*') count++; } char *result = (char *)malloc(strlen(str) - count + 1 * sizeof(char)); for (int i = 0, j = 0; i < strlen(str); i++) { if (str[i] != '*'){ result[j++] = str[i]; result[j++] = str[i]; } } printf("original: %s\nnew: %s\n", str, result); free(result); return 0; } C #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, const char * argv[]) { char *str = "sdafsf*fsf**fs"; int count = 0; for (int i = 0; i < strlen(str); i++) { if (str[i] == '*') count++; } char *result = (char *)malloc(strlen(str) - count + 1 * sizeof(char)); for (int i = 0, j = 0; i < strlen(str); i++) { if (str[i] != '*'){ result[j++] = str[i]; result[j++] = str[i]; } } printf("original: %s\nnew: %s\n", str, result); free(result); return 0; }
#include <stdio.h> #include <string.h> int main(){ const char *line = "Exa*mple*"; int n = 0; for(int i = 0; i < strlen(line); i++) n++; char new[(strlen(line) - n)*2]; for(int i = 0, g = 0; i < strlen(line); i++) { if(line[i] != '*'){ new[g] = line[i]; new[++g] = line[i]; } } new[strlen(new) - 1] = '\n'; printf("%s", new); return 0; }