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
Are local variables initialized to zero by default in c?
What is stack in c?
How can you restore a redirected standard stream?
What are c preprocessors?
can any one tel me wt is the question pattern for NIC exam
Write a program to check palindrome number in c programming?
What is bubble sort technique in c?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What does struct node * mean?
What is the difference between null pointer and wild pointer?
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
What is the process of writing the null pointer?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
How can I read a binary data file properly?
What does c mean in basketball?