Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
C Program to Invert Bits of a Non-Negative Number using Getopt()

Write a C program that inverts the bits of a non-negative number provided by the user through argument. Note, the program is to invert the order of the bits, i.e., move the lowest bit to the highest position, 2nd lowest bit to 2nd highest position, etc. It is not to flip the bits (0à1, 1à0). The program prints out the number, its binary representation, the value after the inversion, and the binary representation after the inversion. Your program can assume that the number is a 32-bit unsigned integer (i.e., a number in [0, 232 – 1]).  Write a C program that uses getopt() to parse its command line. Refer to the example program for getopt() in the slides. Assume that you were writing a program named my_uniq to report or filter out repeated lines in a file (the same as the uniq tool in Linux).The arguments in the command lines are also the same as those for uniq:my_uniq [−c|−d|−u] [−f fields] [−s char] [input_file [output_file]] Your program is to extract the options, option parameters, and other arguments in the command line.

Write a C program that sorts the environment variables passed to the program based on environment variable names. In the class, you were shown with a program printing out all the environment variables passed to the program. Each environment variable has a variable name (the part before the '=' sign) and the a variable value (the part after the '=' sign). For example, the
following three entries in envp (i.e., three environment variables), the names are USER,PWD, and HOME, respectively, and the values are ubuntu, /tmp, and /home/ubuntu.

envp[5] = "USER=ubuntu"
envp[6] = "PWD=/tmp"
envp[7] = "HOME=/home/ubuntu"


Your program needs to sort the environment variables. To get the environment variables, your program may use strtok(). The program can directly sort the environment variables by exchanging the pointers saved in envp. You may also choose to create another data structure of your choice (e.g., another array of pointers, or linked list). But, no matter which method you choose, your program must print out the environment variables, including their names and values, in ascending order determined by applying strcmp() on their names. For example, the three entries above are sorted by calling strcmp() to compare USER, PWD,
and HOME. Since the strcmp() calls determine that "HOME" < "PWD" and "PWD"<"USER",your program should print out
HOME=/home/ubuntu
PWD=/tmp
USER=ubuntu

support
close