# beginner plzz help urgent

• 01-14-2007
sara101
beginner plzz help urgent
THIS code is of SMurf & corrected by swoopy

plzzz can some one give me whole program means its main function & also comments on each line which help me in understanding this prog as i cant understand
why
rshift = 6;
this take & while (src - in < 17280)this also why only 17280?
& also not understand some function also so plzzzzzz help me in this regard & plzz give me main function with comments if u can
its urgent plzz.

Hello,

I'm trying to write two small functions that compresses/decompresses 7-bit data that is packed together into 8 bits. These are my alogrithms:-

insert
Code:

```Code: int compress(unsigned char *in, unsigned char *out) {         unsigned char *src, *dest, mask1, mask2;         int lshift, rshift;         src = in;         dest = out;         while (src - in < 17280) //size of imput data         {                 mask1 = 0x7F;                 mask2 = 0x40;                 rshift = 6;                 for (lshift=1;lshift<8;lshift++)                 {                         *dest = ( (*(src++) & mask1) << lshift);                         *dest++ |= ((*src & mask2) >> rshift--);                         mask1 >>= 1;                         mask2 |= (mask2 >> 1);                 }                 src++;         }         return 0; } int decompress(unsigned char *in, unsigned char *out) {         unsigned char *src, *dest, mask1, mask2;         int lshift, rshift;         src = in;         dest = out;         while (src - in < 17280) //size of imput data         {                 mask1 = 0x00;                 mask2 = 0xFE;                 rshift = 1;                 for (lshift=7;lshift>=0;lshift--)                 {                         if (lshift == 7)                                 *dest++ |= ((*src & mask2) >> rshift++);                         else                         {                                 *dest = ((*(src++) & mask1) << lshift);                                 *dest++ |= ((*src & mask2) >> rshift++);                         }                         mask1 <<= 1;                         mask1++;                         mask2 <<= 1;                 }         }         return 0; }```
• 01-14-2007
Salem
Yeah - thanks for bumping 4 year old threads. Try reading some forum rules.

Here's what I think of your illiterate use of 'z'
http://www.catb.org/~esr/faqs/smart-...html#writewell

And on urgency - it's your problem, not mine.
http://www.catb.org/~esr/faqs/smart-...ns.html#urgent

Decided it's time for a bit of a clamp-down on the recent spate of people bumping and slopping "urgent" all over their posts.

> can some one give me whole program means its main function & also comments on each line
I dunno - maybe trying to do your own homework first and posting an attempt rather than expecting to luck upon a fully documented answer you can just hand it in.

As for the rest of it, simple things like & and 0x notation should be explained in any half-decent C book - read yours.
• 01-14-2007
sara101
if you tell me itss very big thing for me but for you its nothing as you are perfect
plzz help
• 01-14-2007
Wraithan
Learn to type legibly, learn to do your own (home)work. Reading this code wont help you at all if you don't know the basics, which using bit masks is.

You don't need the main as the main would be simple, it would have 2 unsigned char arrays, one that is the data to encode, and one that would hold the encoded data.

This is far beyond what you would understand at that point so go learn to do much more simple things such as the tutorials on this site.
• 01-14-2007
sara101
so this should be its main
insert
Code:

```#include<stdio.h> #include<conio.h> compress(unsigned char *in, unsigned char *out); void main(void) { clrscr(); unsigned char ff[]={1,2,3}; for(int a=1;a<=2;a++) compress(&ff[a],&ff[a+1]); }```
just plzz tell it is right main for the above compress function or not & plzz tell me how i take

output of compress data plzz just tell me that only .
• 01-14-2007
manutd
Code:

`void main(void)`
*heart failure* No, no, no, no, no:
Code:

`int main (void)`
• 01-14-2007
sara101
hi

just plzz tell that the main() which i post in topic was right

for the that compress function or not & plzz tell me how i

take output of compress data plzz just tell me that only .

me in this regard.
thanks
• 01-14-2007
Wraithan
Comment that, I want to know why you used a for loop right there.

Randomly guessing at what should be there is the worst possible way to try and figure out how to use something. You obviously want to use some sort of compression, why not just use zlib, it is a library that has plenty of ways to compress data.

Really like I said above (which you didn't read if my guess is correct) this is too advanced for you, go learn other stuff first. If this is for a class, then you need to talk to your teacher/counselor about when you can go in for extra help or how you can go about transferring to a lower level class. That code that you are trying to use is not C++ 101 level stuff, (granted it isn't much higher than that, but wouldn't be in a first course).

Get yourself a good C book (there are plenty recommended above.

Also, it is 'please' not 'plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' stop the internet dude talk, it just makes you look ignorant(if not stupid) and immature, and this is a pretty mature place where people have mature conversations. (Even if in real life you are immature half the time, like me, show you can talk like an adult)
• 01-14-2007
manutd
Speak english, for god's sakes! Also, I won't tell you the main you posted is right if it isn't! Yeesh!
• 01-14-2007
swgh
void main ( pointed out by manutd ) is incorrect. Your code does not make any sense in the slightest, and people can't understand it. conio.h is non-standard, and the compress function does little to boost the code meaning.

Read all the above replys and get a beginners C book. You should do somthing like this:

Code:

```#include <stdio.h> int main ( void ) // correct main {   printf("Hello World");   getchar();   return 0; }```
Before you tackle anything more advanced.
• 01-14-2007
ssharish2005
Code:

`compress(unsigned char *in, unsigned char *out);`
Here is a question for you. Why dint you specify the return type of this function. If you give me the answer right, definitly u will get the program working a bit. Depends. But what is it by default??;)

ssharish2005
• 01-14-2007
vart
Code:

```for(int a=1;a<=2;a++) compress(&ff[a],&ff[a+1]);```
array are indexed from 0
ff[0], ff[1], ff[2] are valide expressions

ff[1],ff[2] on the first iteration
and
[ff2] ff[3]
on the second, ff[3] is out of bounds access

Code:

`compress(unsigned char *in`
if this is in value - why do you need pass it by pointer?
if this isn't in value - why to use such a name?

ff[1] - is in
ff[2] - is out - so is it overwritten?
and is used as an in on the next iteration? Just wondering