#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int sort(const void* a, const void* b)
{
return (isdigit(*(char*)a) && isdigit(*(char*)b) ) ? *(char*)a > *(char*)b : 0;
}
int main()
{
char* arr = (char*) malloc (sizeof(char) * 1024);
if(arr != 0)
{
printf("Input the string:");
gets(arr);
if(arr != 0)
{
char* str = (char*)malloc(strlen(arr) * sizeof(char));
char* c[2] = {arr, str};
do
{
if(isdigit(*c[0]))
{
*(c[1]++) = *c[0] ;
}
}while(*((c[0])++) != 0);
*(c[1]++) = 0;
qsort((void*)str, strlen(str), sizeof(char), sort);
printf("%s", str);
free(str);
}
}
free(arr);
return 0;
}
Comments