answersLogoWhite

0

#include "stdio.h"

#include "stdlib.h"

#include "string.h"

#define MAX 50

#define N 2000

void sort_words(char *x[], int y);

void swap(char **, char **);

int main(void)

{

char word[MAX];

char *x[N];

int n = 0;

int i = 0;

for(i = 0; scanf("%s", word) == 1; ++i)

{

if(i >= N)

printf("Limit reached: %d\n", N), exit(1);

x[i] = calloc(strlen(word)+1, sizeof(char));

strcpy(x[i], word);

}

n = i;

sort_words(x, n);

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

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

return(0);

}

void sort_words(char *x[], int y)

{

int i = 0;

int j = 0;

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

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

if(strcmp(x[i], x[j]) > 0)

swap(&x[i], &x[j]);

}

void swap(char **p, char **q)

{

char *tmp;

tmp = *p;

*p = *q;

*q = tmp;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

How do you write a program that accepts 5 integers in an array and shows the average of 3?

To write a program that accepts 5 integers in an array and calculates the average of the first three, you can follow these steps: First, create an array to hold the 5 integers. Then, prompt the user to input the integers and store them in the array. Finally, compute the average of the first three integers by summing them and dividing by 3, and display the result. Here’s a simple example in Python: numbers = [int(input(&quot;Enter integer {}: &quot;.format(i + 1))) for i in range(5)] average = sum(numbers[:3]) / 3 print(&quot;Average of the first three integers:&quot;, average)


Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


What is Arrays of Pointers?

An array of pointers is a contiguous block of memory that contains pointers to other memory locations. They essentially allow non-contiguous memory locations to be treated as if they were an actual array.


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.

Related Questions

How do you write a program that accepts 5 integers in an array and shows the average of 3?

To write a program that accepts 5 integers in an array and calculates the average of the first three, you can follow these steps: First, create an array to hold the 5 integers. Then, prompt the user to input the integers and store them in the array. Finally, compute the average of the first three integers by summing them and dividing by 3, and display the result. Here’s a simple example in Python: numbers = [int(input(&quot;Enter integer {}: &quot;.format(i + 1))) for i in range(5)] average = sum(numbers[:3]) / 3 print(&quot;Average of the first three integers:&quot;, average)


What will be the program to arrange numbers stored in array in ascending order using pointers?

sorry


Why array is a implicit pointer?

An array of pointers is exactly what it sounds like - one or more pointers arranged in order in memory, accessible through a common base name and indexed as needed. Philosophically, there is no difference between an array of pointers and an array of objects...int a[10]; // 10 integers, named a[0], a[1], a[2], ..., a[9]int *b[10]; // 10 pointers to int, named b[0], b[1], b[2], ..., b[9]If you initialize the array of pointers...int i;for (i = 0; i < 10; i++) b[i] = &a[i];... then *b[0] would be the same as a[0], etc.


What is an array pointers?

I guess it is an 'array of pointers'. Example:int main (int argc, char *argv[])


8086 assembly program to sort a list of integers?

assembly language program for sorting an array using 8086 microprocessor.


How do you write a program that accepts 50 integer values and sort them in basic programming?

Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.


What is Arrays of Pointers?

An array of pointers is a contiguous block of memory that contains pointers to other memory locations. They essentially allow non-contiguous memory locations to be treated as if they were an actual array.


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.


How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


What is Jagged Array in C?

A Jagged array is an array of arrays. You can initialize a jagged array as &minus; int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}}; Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers.