Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact:
Offline PMPoints:
7,319.40
have a function that will allocate space to store a value of desired length (at least 4 and 24, but feel free to test it with larger numbers: 32, 40, 64, etc.) and return the address (so we can assign it to one of our pointers).
anyone got an idea?
using a malloc line?
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact:
Offline PMPoints:
7,319.40
<code>
unsigned char *value;
value = (unsigned char *) malloc (sizeof(unsigned char) * 4);
</code>
can anyone English these two lines for me?
Group: Members
Posts: 26,993
Joined: Aug 30 2006
Contact:
Offline PMPoints:
1,959.57
begin code
multiply a number (0-255) by a value
value equals a number (0-255) multiplied by the 4x the number of bytes that the number (0-255) is, the same number of which is being allocated to memory
end code
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact:
Offline PMPoints:
7,319.40
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
unsigned char *value;
value = (unsigned char *) malloc (sizeof(unsigned char) * 4);
*(value+0) = *(value+1) = *(value+2) = *(value+3) = 0;
int num1, num2, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &num1, &num2);
add = num1 + num2;
subtract = num1 - num2;
multiply = num1 * num2;
divide = num1 / (float)num2;
printf("Sum = %d\n", add);
printf("Differnece = %d\n", subtract);
printf("Multiplication = %d\n", multiply);
printf("Division = %.2f\n", divide);
return(0);
}
this is my program so far.
I need too accomplish this still...
have a function that will allocate space to store a value of desired length (at least 4 and 24, but feel free to test it with larger numbers: 32, 40, 64, etc.) and return the address (so we can assign it to one of our pointers).
implement a function that accepts as two arguments two of our dynamically allocated “numbers”, compares them, and returns a -1 if the left parameter is greater, 0 if they are equal, and 1 if the right parameter is greater.