0

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.

yarden
  • 31
  • 3

1 Answers1

1

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?

netskink
  • 4,033
  • 2
  • 34
  • 46
  • 1
    its unlikely that supplying words in the command line is what the user wants. The 'hard' parts (parsing and dynamic array allocation) are already done too. – pm100 May 19 '22 at 17:38
  • perhaps pm100, lets try to encourage the new user (@yarden) to ask a question with code and current output. Afterwards we can help solve their problem. What do you say? – netskink May 19 '22 at 17:46