c sort input by Lexicographic order without knowing the number of words in advance

79 views Asked by At

i would like to solve this problem: the user gives an input of words, separated by ', '. i don't know how many words he would give. the output should be: all words are sorted by a Lexicographic order. i also need to have an access to this output for later.

example: user input: banana, apple, soap, door (as one string, could have any number of words) output: apple banana door soap thanks a lot for helping.

1

There are 1 answers

2
netskink On

Lets work on it together. Try this for a start. You can use it to update your question.

#include <stdio.h>

int main(int argc, char *argv[]) {

  int i;

  for(i=1; i<argc; i++) {
    printf("word %d is %s\n", i, argv[i]);
  }
}

The usage and output is like so:

$ ./testy aword, anotherword
word 1 is aword,
word 2 is anotherword

Notice how the "," is part of the word? Notice how the words are determined by the space between program args? Think you can expand on it?