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
How would you reduce or minimize the size of a "file"?
beks73 [17]
The answer is D Compress

I hope this helps
6 0
3 years ago
Which of the following operations would best allow you to place 3D building models at their proper height on the terrain (e.g.,
arsen [322]

Answer:

The answer is "Option C"

Explanation:

Base heights are related to it as measurements of height or z-values as they are extracted by mathematics which serves to define the ground of that same world. Once applying a datatype, it can be any entire amount, that will become the level of the function in meters beyond the ground, and wrong choices can be described as follows:

  • In option A, It is a part of extra dimensions object, that's why it is wrong.
  • In option B, It wrong because the offset tool allows the quick and easy offsetting of the lines.
  • In option D, It emphasizes the recovery charts, that's why it is incorrect.
5 0
3 years ago
"The _____ of the Open Systems Interconnection (OSI) model generates the receiver’s address and ensures the integrity of message
aleksklad [387]

Answer:

The transport layer

Explanation: Layer 4, is the transport layer of the Open System Interconnection (OSI), that handles message transfer of data between end systems or hosts and ensures complete packets transfer.

7 0
3 years ago
Read 2 more answers
Matthew is running a study on the effects of room temperature on performance on an algebra test. One group takes the test in a r
qaws [65]

Answer:

Independent variable is temperature

Explanation:

An equation has this form:    Y= f(x), where Y is dependent variable andX is independent variable.

In this case Y ( Dependent variable) is Perfomance in test, an it depends on x(Independent variable) wich is temperature.

7 0
3 years ago
The benefits for a cad proram is: (points : 2) 1 accuracy 2 repeatability 3 simplicity 4 all of the above
NARA [144]
<span>ALL OF THE ABOVE. The benefits for a CAD program is accuracy, repeatability, simplicity.</span>
4 0
3 years ago
Other questions:
  • Describe what is meant by the following:
    14·1 answer
  • Question 5 (10 points)
    12·1 answer
  • If we collect data on the number of wins each team in the NFL had during the 2011-12 season, we have _____________ data.
    10·1 answer
  • What is an Apple Pen?
    5·2 answers
  • What is the difference between a switch and a hub?
    8·1 answer
  • What is ana absolute adress
    11·1 answer
  • What are the defenses to protect against these attacks?
    13·1 answer
  • Write a function in Java to implement the following logic:
    13·1 answer
  • What is the plan to make optimum usage of available spaces?
    15·1 answer
  • Website managers use____ every day.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!