1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Yuki888 [10]
3 years ago
13

Write a program, named sortlist, that reads three to four integers from the command line arguments and returns the sorted list o

f the integers on the standard output screen. You need to use strtok() function to convert a string to a long integer. For instance,
Computers and Technology
1 answer:
yawa3891 [41]3 years ago
7 0

Answer:

In C++:

void sortlist(char nums[],int charlent){    

   int Myarr[charlent];

const char s[4] = " ";  

char* tok;  

tok = strtok(nums, s);  

int i = 0;  

while (tok != 0) {  

 int y = atoi(tok);

 Myarr[i] = y;

 tok = strtok(0, s);  

 i++;

}  

int a;  

for (int i = 0; i < charlent; ++i) {

for (int j = i + 1; j < charlent; ++j) {

 if (Myarr[i] > Myarr[j]) {

  a =  Myarr[i];

  Myarr[i] = Myarr[j];

  Myarr[j] = a;

       }   }  }

 

for(int j = 0;j<charlent;j++){ printf(" %d",Myarr[j]); }  

}

Explanation:

This line defines the sortlist function. It receives chararray and its length as arguments

void sortlist(char nums[],int charlent){    

This declares an array

   int Myarr[len];

This declares a constant char s and also initializes it to space

const char s[4] = " ";  

This declares a token as a char pointer

char* tok;

This line gets the first token from the char

tok = strtok(nums, s);

This initializes variable i to 0

int i = 0;

The following while loop passes converts each token to integer and then passes the tokens to the array  

<em> while (tok != 0) {  </em>

<em>  int y = atoi(tok); </em><em>-> Convert token to integer</em><em> </em>

<em>  Myarr[i] = y; </em><em>-> Pass token to array</em><em> </em>

<em>  tok = strtok(0, s); </em><em>-> Read token</em><em> </em>

<em>  i++; </em>

<em> }  </em>

Next, is to sort the list.

int a;

This iterates through the list  

for (int i = 0; i < charlent; ++i) {

This iterates through every other elements of the list

for (int j = i + 1; j < charlent; ++j) {

This condition checks if the current element is greater than next element

 if (Myarr[i] > Myarr[j]) {

If true, swap both elements

<em>   a =  Myarr[i]; </em>

<em>   Myarr[i] = Myarr[j]; </em>

<em>   Myarr[j] = a; </em>

       }   }  }

The following iteration prints the sorted array

<em>for(int j = 0;j<charlent;j++){ printf(" %d",Myarr[j]); }  </em>

}

<em>See attachment for illustration of how to call the function from main</em>

Download cpp
You might be interested in
What are some other features of sending attachments in Outlook 2016? Check all that apply.
Elis [28]

Answer:

the answer is a, b,d on edg.

Explanation:

8 0
2 years ago
Read 2 more answers
Putting commands in correct order so computers can read the commands
lana66690 [7]

Answer:

its b I think I'm pretty sure

8 0
2 years ago
Tractor in reverse brainliest answer
abruzzese [7]

Answer:

Valtra

Explanation:

It is the only tractor that goes in reverse.

Thank you so much!

Have a good day

Hope this helped,

Kavitha Banarjee

5 0
2 years ago
Combination of star topology and star topology can consider as hybrid?​
Ad libitum [116K]

Answer:

no

Explanation:

A hybrid topology is a type of network topology that uses two or more differing network topologies. These topologies can include a mix of bus topology, mesh topology, ring topology, star topology, and tree topology.

4 0
2 years ago
__________for about 10 minutes in between each repetition session helps you to remember the information better. a. Reading c. Sl
k0ka [10]

the answer is a.) reading

6 0
2 years ago
Read 2 more answers
Other questions:
  • Can someone please help me write a code for this
    7·1 answer
  • How is sharepoint used in organization today?
    12·1 answer
  • Earthquakes happen in the Earth’s
    10·1 answer
  • Which of the following is an accurate statement? When the LOWER function is used in a SELECT clause, it will automatically store
    6·1 answer
  • State and give reason, if the following variables are valid/invalid:
    12·1 answer
  • "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequen
    10·2 answers
  • Write the line of code to calculate the area of a circle with radius 3 and store it in a variable called
    10·1 answer
  • Use the drop-down menus to complete statements about audio file formats.
    10·1 answer
  • I need the full code for 6.1.3 code hs circles and squares please answer please help
    12·1 answer
  • What is an advantage of using a dynamic hard drive in a vm?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!