Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I think I\'v got the first printf() statement justified correctly like so: print

ID: 3637596 • Letter: I

Question


I think I'v got the first printf() statement justified correctly like so: printf("%10d %0#10X ",(int)f,(int)f); but Im not sure how to do the same to the 2nd printf() statement. Let me know what you think! THanks!!

########################################################################################

// do not change this code except in the following ways:
// * write code for the following functions:
// * bigOrSmallEndian()
// * getNextFloat()
// * printLinesForNumber()
// * change studentName by changing "I. Forgot" to your actual name

#include <stdio.h>
#include <stdlib.h>
static char *studentName = "I. Forgot";

// report whether machine is big or small endian
void bigOrSmallEndian()
{
int num = 1;
if(*(char *)&num == 1)
{
printf("Byte Order: Little-Endian ");
}
else
{
printf("Big-Endian ");
}



}

// get next float using scanf()
// returns 1 (success) or 0 (failure)
// if call succeeded, return float value via f pointer
int getNextFloat(float *f)
{
// replace this code with the call to scanf()
scanf("%f",f);
return 1; // in C, a zero value means false, anything else means true
}

// print requested data for the given number
void printNumberData(float f)
{printf("%d %0#10X ",(int)f,(int)f);
printf("%.2f %0#10X ",f,*(int *)&f);
}

// do not change this function in any way
int main(int argc, char **argv)
{
float f; // number currently being analyzed
int nValues; // number of values successfully parsed by scanf

printf("scanf and printf in c!!!!!!!!!!!!!!!!!!!%s ", studentName);
bigOrSmallEndian();
for (;;) {
if (argc == 1) // allow grading script to control ...
printf("> "); // ... whether prompt character is printed
nValues = getNextFloat(&f);
if (! nValues) { // encountered bad input
printf("bad input ");
while (getchar() != ' ') ; // flush bad line from input buffer
continue;
}
printNumberData(f);
if (f == 0.0)
break;
}
printf(" ");
return 0;
}

Explanation / Answer

please rate - thanks

message me if any problems

// do not change this code except in the following ways:
// * write code for the following functions:
// * bigOrSmallEndian()
// * getNextFloat()
// * printLinesForNumber()
// * change studentName by changing "I. Forgot" to your actual name

#include <stdio.h>
#include <stdlib.h>
static char *studentName = "I. Forgot";

// report whether machine is big or small endian
void bigOrSmallEndian()
{
int num = 1;
if(*(char *)&num == 1)
{
printf("Byte Order: Little-Endian ");
}
else
{
printf("Big-Endian ");
}



}

// get next float using scanf()
// returns 1 (success) or 0 (failure)
// if call succeeded, return float value via f pointer
int getNextFloat(float *f)
{
// replace this code with the call to scanf()
scanf("%f",f);
return 1; // in C, a zero value means false, anything else means true
}

// print requested data for the given number
void printNumberData(float f)
{printf("%10d %0#10X ",(int)f,(int)f);
printf("%10.2f %0#10X ",f,*(int *)&f);
}

// do not change this function in any way
int main(int argc, char **argv)
{
float f; // number currently being analyzed
int nValues; // number of values successfully parsed by scanf

printf("scanf and printf in c!!!!!!!!!!!!!!!!!!!%s ", studentName); //corrected it
bigOrSmallEndian();
for (;;) {
if (argc == 1) // allow grading script to control ...
printf("> "); // ... whether prompt character is printed
nValues = getNextFloat(&f);
if (! nValues) { // encountered bad input
printf("bad input ");
while (getchar() != ' ') ; // flush bad line from input buffer
continue;
}
printNumberData(f);
if (f == 0.0)
break;
}
printf(" ");
return 0;
}