Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int getLengthNum(char* str, int i) {
- int len = 0;
- short cBool = 0;
- do {
- if ((str[i] > 47 && str[i] < 58) || (len == 0 && str[i] == 45)) {
- len++;
- i++;
- }
- else
- cBool = 1;
- } while (cBool == 0);
- return len;
- }
- void findNumbers(char* str, char* numbers) {
- int len = 0;
- int counter = 0;
- for (int i = 0; i < strlen(str); i++) {
- len = getLengthNum(str, i);
- if (len != 0) {
- for (int j = 0; j < len; j++) {
- numbers[counter] = str[i + j];
- counter++;
- }
- numbers[counter] = ',';
- counter++;
- i += len - 1;
- len = 0;
- }
- }
- }
- int main() {
- printf("Enter the string: ");
- char str[80];
- gets(str);
- char* numbers = malloc(80);
- findNumbers(str, numbers);
- printf("Result - ");
- int i = 0;
- while (numbers[i] > 0) {
- printf("%c", numbers[i]);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement