DIGIT-ARC read-only archive · snapshot: July 23, 2026

C programming help

5 posts · originally from https://geek.digit.in/community/threads/c-programming-help.6471/

godsownman
godsownman Original post #1
Mar 5, 2005 at 6:17 PM
Please can you tell me how I can mergesort two arrays alphabetically and then print them?

If that is slightly difficult it will be fine if you can just tell me how to sort alphabetically forget the array part .

I need this for the language C only .

Thanks

Regards.
vysakh
vysakh #2
Mar 5, 2005 at 8:06 PM
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
char st1[100],st2[100],tmp;
int i,j,len;
printf("Enter 2 strings:\n");
gets(st1);
gets(st2);
strcat(st1,st2);
len=strlen(st1);
printf("\n\n\n");
for(i=0;i<len;i++)
for(j=0;j<=i;j++)
if(st1<st1[j])
{
tmp=st1;
st1=st1[j];
st1[j]=tmp;
}
puts(st1);
getch();
}
godsownman
Mar 6, 2005 at 6:58 PM
Thanks

vysakh

Thanks for your help but thats of not much use to me because i need to sort words according to their alphabetical order and not the alphabets of the word or the sentences that are entered.

Your code is not serving my purpose.

However thanks a lot for the prompt help. Its appreciated.

Thanks .

Please help me anybody.....
hafees
hafees #4
Mar 7, 2005 at 1:40 AM
do u specifically want merge sort?? then i need to refer. i will post it later if u want. here is the bubble sort function.

void bubble_sort(char *a[],int n)
{
int i,j;
char temp[20];
for(i=0;i<n;i++)
{
for(j=1;j<(n-i);j++)
{
if(strcmp(a[j-1],a[j])>0)
{
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
}

}
}

//use strcmpi() if u want a case insensitive search
//n is the number elements in the array
//strcpy is used to copy the string
godsownman
Mar 7, 2005 at 7:01 PM
Yes

Yes I need merge sort specifically merge sort .
Please try.



Thanks sorry for the trouble.

Regards