You are on page 1of 5

Dynamic Allocation and

Alphanumreic Strings
Dynamic Allocation of memory to sort the strings
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int *a,n,i,j,t;
clrscr();
printf("\nEnter the number of integers to be sorted in ascending order: ");
scanf("%d",&n);
a=(int *)malloc(n *sizeof(int));
printf("\nEnter the %d numbers to be sorted in ascending order one by one: ",n);
for(i=0;i<=n-1;i++)
{
scanf("%d", (a+i));
}
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if(*(a+i)<*(a+j))
{
t=*(a+i);
*(a+i)=*(a+j);
*(a+j)=t;
}
}
}
printf("\nAfter sorting in ascending order: ");
for(i=0;i<n;i++)
printf("\n%d",*(a+i));
getch();
}
Program to split Alphabet and Numric from
Alphanumeric String
#include<stdio.h>
#include<stdlib.h>

int main()
{
char str[] = "12abc12";

int alphabet = 0, number = 0, i;


for (i=0; str[i]!= '\0'; i++)
{
// check for alphabets
if (isalpha(str[i]) != 0)
alphabet++;
// check for decimal digits
else if (isdigit(str[i]) != 0)
number++;
}

printf("Alphabetic_letters = %d, "


"Decimal_digits = %d\n", alphabet, number);

return 0;
}

You might also like