Hi all,
I want to sort a string alphabetically.
For eg:
I the input is : I love my country.
The output should be : I country love my.
Here is my code. I tried storing each word into a 2-D array. But its showing some errors. Plz help!!!!
thnx
Code:
#include<stdio.h>
#include<string.h>
main()
{
int i,j,n,len,len1,k=0,z=0,x;
char str[50],temp,a[50][50];
printf("Enter the string :");
scanf("%[^\n]",str);
for (i=0;i<len1;i++)
{
if (str[i] != '\0')
{
a[k][z] = str[i];
k++;
z++;
}
}
a[k][z]='\0';
}
for (x = 0; a[x]!='\0'; x++) { }
len=i;
printf("len =%d",len);
The length is correct. But output I'm getting are some garbage values...