answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

int i,j,d;

char ch[20],temp;

clrscr();

printf("\nEnter the no.of string:");

scanf("%d",&d);

printf("\nEnter the strings:");

for(i=0;i<d;i++)

{

gets(ch[i])

}

printf("\nThe strings are:");

for(i=0;i<d;i++)

{

printf("\n%s",ch[i]);

}

for(i=0;i<d;i++)

{

for(j=i+1;j<d;j++)

if(ch[i]>ch[j])

{

temp=ch[i];

ch[i]=ch[j];

ch[i]=temp;

}

}

getch();

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

#include<string.h>

int main(){

int i,j,n;

char str[20][20],temp[20];

puts("Enter the no. of string to be sorted");

scanf("%d",&n);

for(i=0;i<=n;i++)

gets(str[i]);

for(i=0;i<=n;i++)

for(j=i+1;j<=n;j++){

if(strcmp(str[i],str[j])>0){

strcpy(temp,str[i]);

strcpy(str[i],str[j]);

strcpy(str[j],temp);

}

}

printf("The sorted string\n");

for(i=0;i<=n;i++)

puts(str[i]);

getch();

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include

#include

#include

using namespace std;

void sortString(char array[], int num);

void outputString(char array[], int num);

int main() {

int columns=30, rows=0;

char filename[30], letter;

ifstream fin;

cout << "Enter the file name: ";

cin >> filename;

fin.open(filename);

if (!fin) {

cout << "Failure to open the file.";

} else {

while (fin >> letter) {

if (letter == '\n')

rows++;

}

fin.clear();

fin.seekg(0,ios::beg);

char name[rows][columns];

rows = 0;

while (fin.get(name[rows][columns])) {

rows++;

}

sortString(name, rows+1);

outputString(name, rows+1);

}

return 0;

}

void sortString(char array[], int num) {

int i, j;

char check[num][30];

for (i=1; i

strcpy(check, array[i][30]);

for (j=1; j>=1 && (strcmp(check, array[30][j-1])==1); j--) {

array[j][30] = array[j-1][30];

array[j-1][30] = check;

}

}

}

void outputString(char array[], int num) {

for (int i=0; i

cout << array[i][30] << endl;

}

}

The above would be correct if the question required a C++ solution. The code could not be compiled with a C compiler.

Rows is is initialized to zero and the next time rows is referenced is

char name[rows][columns];

And as soon as

while (fin.get(name[rows][columns])) {

rows++;

}

is executed the program will crash.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

#include <stdio.h> #include <conio.h> #include <string.h> void main() { char name[10][8], Tname[10][8], temp[8]; int i, j, N; clrscr(); printf("Enter the value of N\n"); scanf("%d", &N); printf("Enter %d names\n", N); for(i=0; i< N ; i++) { scanf("%s",name[i]); strcpy (Tname[i], name[i]); } for(i=0; i < N-1 ; i++) { for(j=i+1; j< N; j++) { if(strcmpi(name[i],name[j]) > 0) { strcpy(temp,name[i]); strcpy(name[i],name[j]); strcpy(name[j],temp); } } } printf("\n----------------------------------------\n"); printf("Input Names\tSorted names\n"); printf("------------------------------------------\n"); for(i=0; i< N ; i++) { printf("%s\t\t%s\n",Tname[i], name[i]); } printf("------------------------------------------\n"); } /* End of main() */

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

#include<iostream> #include<set>

#include<string>

int main()

{

using namespace std;

multiset<string> strings;

string input;

cout << "Enter strings in any order (end with empty string):\n" << endl;

while (getline(cin, input))

{

if (input=="")

break;

strings.insert (input);

}

cout << "\nIn ascending order:\n" << endl;

for (auto s : strings)

cout << s << endl;

}

This answer is:
User Avatar

User Avatar

Programmer

Lvl 2
4y ago

Use strcmp function to compare the strings. A sample C code is available in below link. Just refer it for more information.

s4sourcecode.online/2020/02/c-program-to-sort-list-of-names-in.html?m=1

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program To sort a string in ascending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a VB script to sort a string in ascending order?

uitihyiuiphoiphuihyi


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


Which action do you perform on a data source to reorganize the order of the record for a merge?

You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.You can sort the data in ascending or descending order.


What does it mean to sort a table in ascending order?

To sort from smallest to largest. Ascending means to go up.


What is it called when a feature sorts data into ascending alphabetical or numerical order?

ascending sort


Write a program to sort elements of an array in ascending order?

import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }


What two ways can you sort information?

In ascending order and in descending order.


You can sort numeric fields in ascending order only?

No. They can be sorted either ways. Ascending or Descending.


How do you sort three nondescending numbers?

In ascending order, perhaps!


How do you sort dates in ascending order?

You can sort dates as you would sort regular data, highlight the range and click on sort and pick the order you want.


What does ascending sort order mean?

That they appear in alphabetical order... A, B, C. ... and so on.


What button do you use to put data in a specific order?

The sort buttons. You can use them to sort in ascending order or descending order. One has A above Z with a down arrow enabling you to sort in ascending order. The other has Z above A with a down arrow enabling you to sort in descending order. Once your data is selected, you can click the appropriate button to do the sort you want.