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


Please Help Members By Posting Answers For Below Questions

What is preprocessor with example?

572


Does free set pointer to null?

545


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

658


Can you write the algorithm for Queue?

1536


Is c weakly typed?

560






What are the 3 types of structures?

558


what is a constant pointer in C

657


What are control structures? What are the different types?

584


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

750


Write a program of prime number using recursion.

606


how logic is used

1487


What is infinite loop?

617


How can I change their mode to binary?

680


Explain function?

652


Difference between malloc() and calloc() function?

646