Answer to Question #9441 in C++ for john

Question #9441
what does Modify_it()do? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <sys/time.h> typedef int int32; typedef char int8; void change_it(int8 *output, int8 *input_1, const int8 *input_2, int32 length) { int32 i = 0; for(i=0; i<length; i++) { output[i] = (int8)(input_1[i] ^ input_2[i]); } return; } void itoa( int32 num, int8 *alpha, int32 radix ) { if( radix == 10 ) { sprintf(alpha, "%i", num); } else if( radix == 16 ) { sprintf(alpha, "%X", num); } } int8 *modify_it(int32 modifier, const int8 *input_1, int32 length) { int8 leading[3]; int32 i_leading; int8 * temp_string = NULL; int8 * ret; int32 i = 0; itoa(modifier/2, leading, 10); i_leading = atoi(leading); temp_string = (int8 *) malloc(8); ret = (int8 *) malloc(length); memset(temp_string, 0, 8); temp_string[0] = 0; if( (modifier+1)%2 == 0 ) { temp_string[0] = (int8)((i_leading<<4) + 8); } else { temp_string[0] = (int8)(i_leading<<4); } for(i=0; i<(length>>3); i++) { change_it(ret+i*8, temp_string, input_1+i*8, 8); } free(temp_string); return ret; } int main(int argc, char **argv) { int8 data[32]; memset(data, 0x0A, sizeof(data)); int8 *resp = modify_it(0xFF, data, sizeof(data)); free(resp); return 0; }
Expert's answer
It modifyes the data, so if for example you want tocalculate a CRC and write it to the last word, you could modify the postlink
function

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal