Desolate Carnage
 
Anyone Provide Some C Help?
Archived | Views: 835 | Replies: 11 | Started 12 years, 7 months ago
 
#827134 | Thu - Mar 15 2012 - 13:48:04
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact: Offline PM
Points: 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?
 
#827136 | Thu - Mar 15 2012 - 13:52:19
Group: Members
Posts: 13,90610k
Joined: Apr 28 2007
Contact: Offline PM
Points: 3,331.84
as in C++?
 
#827137 | Thu - Mar 15 2012 - 13:53:52
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact: Offline PM
Points: 7,319.40
no this is a C program
 
#827138 | Thu - Mar 15 2012 - 13:53:53
Group: Loser
Posts: 8,335
Joined: Mar 1 2008
Contact: Offline PM
Points: 179.40
as in C+-?
 
#827139 | Thu - Mar 15 2012 - 13:58:27
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact: Offline PM
Points: 7,319.40
<code>
unsigned char *value;
value = (unsigned char *) malloc (sizeof(unsigned char) * 4);
</code>

can anyone English these two lines for me?
 
#827147 | Thu - Mar 15 2012 - 14:38:27
Group: Members
Posts: 26,99320k
Joined: Aug 30 2006
Contact: Offline PM
Points: 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
 
#827152 | Thu - Mar 15 2012 - 14:56:08
Group: Members
Posts: 13,90610k
Joined: Apr 28 2007
Contact: Offline PM
Points: 3,331.84
Quote (Lax @ Thu - Mar 15 2012 - 13:53:52)
no this is a C program


yeah but its clearly computer code.... thats all i wanted to know. gotcha
 
#827153 | Thu - Mar 15 2012 - 14:56:24
Group: Members
Posts: 13,90610k
Joined: Apr 28 2007
Contact: Offline PM
Points: 3,331.84
Quote (blackjack21 @ Thu - Mar 15 2012 - 14:56:08)
Quote (Lax @ Thu - Mar 15 2012 - 13:53:52)
no this is a C program


yeah but its clearly computer code.... thats all i wanted to know. gotcha


and by clearly i mean clearly clearly but clearly
 
#827161 | Thu - Mar 15 2012 - 16:24:16
Group: Loser
Posts: 8,335
Joined: Mar 1 2008
Contact: Offline PM
Points: 179.40
Quote (blackjack21 @ Thu - Mar 15 2012 - 14:56:24)
Quote (blackjack21 @ Thu - Mar 15 2012 - 14:56:08)
Quote (Lax @ Thu - Mar 15 2012 - 13:53:52)
no this is a C program


yeah but its clearly computer code.... thats all i wanted to know. gotcha


and by clearly i mean clearly clearly but clearly


clrly no way to tell the difference
 
#827238 | Fri - Mar 16 2012 - 12:37:25
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact: Offline PM
Points: 7,319.40
Quote (___ @ Thu - Mar 15 2012 - 14:38:27)
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


does this do this? allocate space to store a value of desired length?
 
#827247 | Fri - Mar 16 2012 - 15:06:44
Group: Members
Posts: 26,99320k
Joined: Aug 30 2006
Contact: Offline PM
Points: 1,959.57
i dont know, i just googled everything
i dont actually know any c at all

http://en.wikipedia.org/wiki/C_dynamic_memory_allocation
 
#827315 | Sat - Mar 17 2012 - 12:58:50
Group: Members
Posts: 1,791
Joined: Mar 7 2007
Contact: Offline PM
Points: 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.
Archived | Views: 835 | Replies: 11 | General Archive Topic List
 
Quit the Internet