Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- int func(char *str)
- {
- int i = 0, j, k = 0, valmul = 0, cnt = 0;
- if (!(str[i] >= '0' && str[i] <= '9' || str[i] == 'x' || str[i] == ' ')) // check if not fit return -1
- return -1;
- for (i = 0; i < strlen(str); i++) // run on the string
- {
- while ((str[k] != ' ') && (str[k] != '\0')) // run if not space and not end string
- {
- if (str[k] == 'x')
- {
- valmul = str[k + 1] - '0';//valmal=the value after the x (-'0' convert to int from char)
- for (j = 0; j < valmul; j++)
- printf("%c", str[k - 1]);//printf the value before x valmul times
- }
- printf("%c", str[k]);
- k++;
- }
- cnt++;//to return how much
- printf("\n");
- i = k++;//to over after the space
- }
- return cnt;
- }
- void main()
- {
- char str[20]; int val;
- gets(str);
- val = func(str);
- printf("%d", val);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement