Question: Why is there no output from my function? void check _ galaxy ( char * galaxy _ pathname ) { FILE * fp = fopen
Why is there no output from my function?
void checkgalaxychar galaxypathname
FILE fp fopengalaxypathname, r;
if fp NULL
perrorFailed to open the file";
exit;
while
int c fgetcfp;
if c EOF
break;
Read magic number and star format
uintt magicnumber uinttc;
if magicnumber INITIALMAGIC
fprintfstderr "error: incorrect first star byte: xx should be xx
magicnumber, INITIALMAGIC;
break;
c fgetcfp;
if c EOF
break;
uintt starformat uinttc;
if starformat STARFORMAT && starformat STARFORMAT && starformat STARFORMAT
fprintfstderr "error: incorrect star format: xx
starformat;
break;
read pathname length
unsigned char pathnamelengthbytes; B
for int i ; i ; i
c fgetcfp;
if c EOF
fclosefp;
return;
pathnamelengthbytesiunsigned charc;
uintt pathnamelength pathnamelengthbytespathnamelengthbytes;
read pathname
char pathname char mallocpathnamelength ;
if pathname NULL
perrorFailed to allocate memory for pathname";
fclosefp;
exit;
for int i ; i pathnamelength; i
c fgetcfp;
if c EOF
freepathname;
fclosefp;
return;
pathnameicharc;
pathnamepathnamelength;
Read content length
unsigned char contentlengthbytes; B
int validbytes ;
for int i ; i ; i
c fgetcfp;
if c EOF
freepathname;
validbytes ;
break;
contentlengthbytesiunsigned charc;
if validbytes
break;
uintt contentlength contentlengthbytes
contentlengthbytes
contentlengthbytes
contentlengthbytes
uinttcontentlengthbytes
uinttcontentlengthbytes;
Read and calculate the hash
uintt calculatedhash ;
for uintt i ; i contentlength; i
c fgetcfp;
if c EOF
break;
calculatedhash galaxyhashcalculatedhash, uinttc;
Read the initial hash
c fgetcfp;
if c EOF
break;
uintt initialhash uinttc;
Compare the calculated hash with the initial hash
if initialhash calculatedhash
printfs correct hash
pathname;
else
printfs incorrect hash xx should be xx
pathname, initialhash, calculatedhash;
freepathname;
fclosefp;
the right situationspace C examplesfiles.galaxy
bin correct hash
hello.txt correct hash
lastgoodbye.txt correct hash
thesedays.txt correct hash
Check the galaxy called exampleshelloworld.badhash.galaxy, which is in the examples directory
space C exampleshelloworld.badhash.galaxy
hello.c correct hash
hello.cpp correct hash
hello.d correct hash
hello.go correct hash
hello.hs correct hash
hello.java correct hash
hello.js correct hash
hello.pl correct hash
hello.py correct hash
hello.rs correct hash
hello.s correct hash
hello.sh correct hash
hello.sql incorrect hash x should be x but mine~space$ space C examplesfiles.gala~space$ space C exampleshelloworld.badhash.gala~space$no output product
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
