I need to take a sentence from input and sort the words
alphabetically using the C programming language.
Note: This is C not C++.
qsort and strtok not allowed
Answer Posted / yogesh bansal
#include <stdio.h>
int main()
{
char arr[100];
int count =0;
int j,i,k;
char temp;
printf("enter the string\n");
gets(arr);
for(i=0;arr[i]!='\0';i++)
count++;
printf("value of count is %d\n",count);
for(k=0;k<=count;k++)
{
for(j=0;j<count-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
puts(arr);
return 0;
}
This is the correct and working program.
| Is This Answer Correct ? | 6 Yes | 23 No |
Post New Answer View All Answers
Why void is used in c?
Why do we use int main instead of void main in c?
What is the difference between call by value and call by reference in c?
What is the difference between Printf(..) and sprint(...) ?
How can a number be converted to a string?
what is the difference between class and unio?
What is an endless loop?
What are the Advantages of using macro
How do you use a 'Local Block'?
What is equivalent to ++i+++j?
What are the advantages of using macro in c language?
using only #include
What is zero based addressing?
What is exit() function?
What’s a signal? Explain what do I use signals for?