memory

N

n.noumia

Write a C/C++ program to extract any fractional decimal number (for
example, 15, 15.0, 0.15 or .15) between the strings "Hello " and "
World!" (for example, "Hello 1.124 World!"), then return a float.
float ExtractFloat(const char *str)
{
....
}

Write a C/C++ function to allocate memory always aligned at a 16 byte
boundary.
int * AllocAlignedMemory(int numBytes)
{
....
}

Write a C/C++ program to reverse the bits in a 32-bit unsigned
integer.
unsigned int ReverseBits(unsigned int u)
{
....
}
 
M

Michael Ekstrand

Write a C/C++ program
<request for homework snipped>

1. There is no such language. There is C, and there is C++, but C/C++
does not exist.
2. Nobody here does other people's homework for them. Please do it
yourself. If you are stuck on a particular problem, feel free to ask
questions here, but please provide the code you're already trying and a
description of your specific difficulty.

- Michael
 
D

Dave Vandervies

1. There is no such language. There is C, and there is C++, but C/C++
does not exist.

I have vague memories of a language called C\C++ that somebody here
implemented, though. He might be thinking of that.
2. Nobody here does other people's homework for them.

Sure we do. I just posted answers for somebody's binary tree homework;
I'm sure his teacher will definitely enjoy reading them, and maybe even
give him some pity marks.


dave
 
K

Keith Thompson

Write a C/C++ program to extract any fractional decimal number (for
example, 15, 15.0, 0.15 or .15) between the strings "Hello " and "
World!" (for example, "Hello 1.124 World!"), then return a float.
float ExtractFloat(const char *str)
{
...
}

Write a C/C++ function to allocate memory always aligned at a 16 byte
boundary.
int * AllocAlignedMemory(int numBytes)
{
...
}

Write a C/C++ program to reverse the bits in a 32-bit unsigned
integer.
unsigned int ReverseBits(unsigned int u)
{
...
}

Give us your instructor's e-mail address so I can submit the solution
directly. Don't worry, I'll be sure to mention your name.

Please provide a reference manual and implementation for this "C/C++"
language. I'm familiar with the C and C++ languages, but not with
"C/C++".

We'll discuss my consulting fees later; you can expect them to be
substantial.

Or you might consider not being a lazy slob and doing your own damned
homework rather than asking others to cheat for you. Just a thought.
 
J

J. J. Farrell

Write a C/C++ program

What is "C/C++"?
to extract any fractional decimal number (for
example, 15, 15.0, 0.15 or .15) between the strings "Hello " and "
World!" (for example, "Hello 1.124 World!"), then return a float.

Why should I? You don't even say please.

Did you have a question about C, or just some orders for us about "C/C+
+"?
 
E

Eric Sosman

Write a C/C++ program to extract any fractional decimal number (for
example, 15, 15.0, 0.15 or .15) between the strings "Hello " and "
World!" (for example, "Hello 1.124 World!"), then return a float.
float ExtractFloat(const char *str)
{
...
}

float ExtractFloat(const char *str) {
/* Returns "a float," as specified */
return 42.0f;
}
Write a C/C++ function to allocate memory always aligned at a 16 byte
boundary.
int * AllocAlignedMemory(int numBytes)
{
...
}

Not possible in portable C.
Write a C/C++ program to reverse the bits in a 32-bit unsigned
integer.
unsigned int ReverseBits(unsigned int u)
{
...
}

unsigned int ReverseBits(unsigned int u) {
/* Reverses the bits of "a" 32-bit unsigned
* integer. To reverse other 32-bit unsigned
* integers, write additional functions.
*/
return 0xd1ef00L;
}
 
B

Beej Jorgensen

Write a C/C++ program to reverse the bits in a 32-bit unsigned
integer.
unsigned int ReverseBits(unsigned int u)
{
...
}

Lookup table. 32 is only 24 more than 8.

-Beej
 
V

vikram Bhuskute

Lookup table. 32 is only 24 more than 8.

-Beej

DOnt you know this guy is our teacher and wanna test
our C skills ..
I gave up ...but why not other give a try huh !!
-vikram
 
R

Richard Heathfield

(e-mail address removed) said:
unsigned int ReverseBits(unsigned int u)
{
...
}

I'll bite.

#include <limits.h>
#include <string.h>
#include <stdlib.h>

unsigned int ReverseBits(unsigned int u)
{
char s[sizeof u * CHAR_BIT + 1] = "";
size_t len = sizeof s - 1;
size_t i = 0;
memset(s, '0', len);
while(i < len)
{
s[i++] = '0' + (n & 1);
n >>= 1;
}
s = 0;

return strtoul(s, NULL, 2);
}

(untested, naturally)
 
B

Barry

Richard Heathfield said:
(e-mail address removed) said:
unsigned int ReverseBits(unsigned int u)
{
...
}

I'll bite.

#include <limits.h>
#include <string.h>
#include <stdlib.h>

unsigned int ReverseBits(unsigned int u)
{
char s[sizeof u * CHAR_BIT + 1] = "";
size_t len = sizeof s - 1;
size_t i = 0;
memset(s, '0', len);
while(i < len)
{
s[i++] = '0' + (n & 1);
n >>= 1;
}
s = 0;

return strtoul(s, NULL, 2);
}

(untested, naturally)


If you want help post complete, compilable code that demonstrates
the problem. LOL
 
F

Francine.Neary

(e-mail address removed) said:
unsigned int ReverseBits(unsigned int u)
{
...
}

I'll bite.

#include <limits.h>
#include <string.h>
#include <stdlib.h>

unsigned int ReverseBits(unsigned int u)
{
char s[sizeof u * CHAR_BIT + 1] = "";
size_t len = sizeof s - 1;
size_t i = 0;
memset(s, '0', len);
while(i < len)
{
s[i++] = '0' + (n & 1);

What is n?
n >>= 1;
}
s = 0;

return strtoul(s, NULL, 2);

}

(untested, naturally)
 
K

Kenneth Brody

Michael said:
1. There is no such language. There is C, and there is C++, but C/C++
does not exist.

int GetLanguage(int C)
{
int Language = C/C++;

return Language;
}

Warning! Do not execute the above code on the DS-9000.

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Kenneth Brody

Richard said:
Barry said:


And if I don't want help? :)

Apparently, your humor is too subtle for at least two readers of
this group.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
R

Richard Heathfield

(e-mail address removed) said:
(e-mail address removed) said:
unsigned int ReverseBits(unsigned int u)
{
...
}

I'll bite.

#include <limits.h>
#include <string.h>
#include <stdlib.h>

unsigned int ReverseBits(unsigned int u)
{
char s[sizeof u * CHAR_BIT + 1] = "";
size_t len = sizeof s - 1;
size_t i = 0;
memset(s, '0', len);
while(i < len)
{
s[i++] = '0' + (n & 1);

What is n?

The Internet is not as reliable as you might think. Sometimes, packets
get shaken around in their long transit over the wire. In extreme
cases, this can result in some characters being turned upside-down.
 
R

Ralf Damaschke

Richard said:
I'll bite.

#include <limits.h>
#include <string.h>
#include <stdlib.h>

unsigned int ReverseBits(unsigned int u)
{
char s[sizeof u * CHAR_BIT + 1] = "";
size_t len = sizeof s - 1;
size_t i = 0;
memset(s, '0', len);
while(i < len)
{
s[i++] = '0' + (n & 1);
n >>= 1;
}
s = 0;

return strtoul(s, NULL, 2);
}

(untested, naturally)


I like that approach, really.
But if e.g. "unsigned int" has the same size as "unsigned long"
and both have as many padding bits as value bits the result is
nearly constant (either 0 or UINT_MAX).

I think that replacing the while-clause by (C99 syntax for
brevity):

for (unsigned chk = 0; chk < (unsigned)-1; chk = (chk << 1) + 1)

would heal that.

If that is right and the homework is not yet overdue I do not
begrudge the OP for gaining some points after he successfully
explained the solution to his teacher.

Ralf
 
R

Richard Heathfield

Ralf Damaschke said:
Richard Heathfield wrote:
I like that approach, really.

You do? :) That is most unexpected - personally I think it sucks, but
I guess it takes all sorts...
But if e.g. "unsigned int" has the same size as "unsigned long"
and both have as many padding bits as value bits the result is
nearly constant (either 0 or UINT_MAX).

Yes, my conscience kept trying to get my attention, yelling "PADDING!"
at me, but I can sometimes be quite skilled at ignoring my conscience.
I think that replacing the while-clause by (C99 syntax for
brevity):

for (unsigned chk = 0; chk < (unsigned)-1; chk = (chk << 1) + 1)

would heal that.

If that is right and the homework is not yet overdue I do not
begrudge the OP for gaining some points after he successfully
explained the solution to his teacher.

And if he managed to correct all those upside-down 'u' characters, it
might even compile.
 
G

Giorgos Keramidas

Ralf Damaschke said:

And if he managed to correct all those upside-down 'u' characters, it
might even compile.

We can always claim that 'some educational buglets were left in, to see
if the reader was paying attention' ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top