Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. int func(char *str)
  6. {
  7.     int i = 0, j, k = 0, valmul = 0, cnt = 0;
  8.     if (!(str[i] >= '0' && str[i] <= '9' || str[i] == 'x' || str[i] == ' ')) // check if not fit return -1
  9.         return -1;
  10.     for (i = 0; i < strlen(str); i++) // run on the string
  11.     {
  12.         while ((str[k] != ' ') && (str[k] != '\0')) // run if not space and not end string
  13.         {
  14.             if (str[k] == 'x')
  15.             {
  16.                 valmul = str[k + 1] - '0';//valmal=the value after the x (-'0' convert to int from char)
  17.                 for (j = 0; j < valmul; j++)
  18.                     printf("%c", str[k - 1]);//printf the value before x valmul times
  19.             }
  20.             printf("%c", str[k]);
  21.             k++;
  22.         }      
  23.         cnt++;//to return how much
  24.         printf("\n");
  25.         i = k++;//to over after the space
  26.     }
  27.     return cnt;
  28. }
  29. void main()
  30. {
  31.     char str[20]; int val;
  32.     gets(str);
  33.     val = func(str);
  34.     printf("%d", val);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement