Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int isValid(char* str)
- {
- int flag = 0;
- if (*str >= '0' && *str <= '9')
- return 0;
- while (*str)
- {
- if (flag == 0)
- {
- if (!((*str >= 'a' && *str <= 'z') || (*str >= 'A' && *str <= 'Z') || (*str >= '0' && *str <= '9')))
- {
- return 0;
- }
- if ((*str >= '0' && *str <= '9'))
- flag = 1;
- }
- str++;
- }
- if (flag == 0)
- return 0;
- else
- return 1;
- }
- char* fun(char* str)
- {
- int count = 0;
- char* tmp,*num,*newStr;
- tmp = str;
- if (isValid(str) == 0)
- return NULL;
- while (*tmp != NULL && !(*tmp >= '0' && *tmp <= '9'))
- {
- count++;
- tmp++;
- }
- //tmp points to the desired num
- num = tmp;
- newStr = (char*)calloc(((int)(*num - '0') * count) + 1, sizeof(char));
- if (!newStr)
- exit(1);
- tmp = str;
- for (int i = 0,k=0; i < (int)(*num - '0'); i++)
- {
- for (int j = 0; j < count; j++)
- {
- *(newStr + (k++)) = *(tmp + j);
- }
- }
- return newStr;
- }
- void main()
- {
- char* str = "Good567Day",*ptr;
- ptr = fun(str);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement