Question: 3. Interactive Integer Hex String Manipulation Rewrite showxbits.c so that it reads integers one at a time from stdin using the library function scanf (the
3. Interactive Integer <-> Hex String Manipulation Rewrite showxbits.c so that it reads integers one at a time from stdin using the library function scanf (the equivalent to printf that does input -- look this up in K&R pg.157). For each integer it reads it should write the input decimal, converted hexadecimal, and the reconverted decimal representations. The hexadecimal output strings requested by showxbits are to be calculated by calling itox(). To generate the reconverted decimal, you can call xtoi(). Use printf with the %x format for integers input, %s format for hex strings you've created. Use the value returned by scanf to end showxbits execution when it scans a non-integer (or EOF). When scanf is properly converting a single value under its conversion %d, it should return 1 (the number of tokens converted). See pg 245, fscanf, end of the first paragraph. The code you need to write in showxbits could look like this: while (scanf("%d", &n) = = 1) { itox( hexstring, n); m = xtoi( hexstring); printf("%12d %s %12d ", n, hexstring, m); } Note: showxbits program should *not* prompt the user for input. "No prompt" is a UNIX convention for reading files from stdin. There's a good reason for the convention. It allows you run showxbits easily and cleanly either by typing in the input data or using input redirection. Create a typescript to show your results. Leave your typescript file in your hw3 directory. You do not need to print it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
