Thread: beginner plzz help urgent

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    5

    Post 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
    mask1 = 0x7F;
    mask2 = 0x40;
    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
    thanks in advance.
    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;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    if you tell me itss very big thing for me but for you its nothing as you are perfect
    plzz help

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    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.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    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 .

  6. #6
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Code:
    void main(void)
    *heart failure* No, no, no, no, no:
    Code:
    int main (void)
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    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 .

    i now read about masking & bitwise operators so just help

    me in this regard.
    thanks

  8. #8
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    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)

  9. #9
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Speak english, for god's sakes! Also, I won't tell you the main you posted is right if it isn't! Yeesh!
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    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.
    Double Helix STL

  11. #11
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    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

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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

    in your code you accessing
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone send me C Socket Programming Tutorial for a beginner?
    By forumuser in forum Networking/Device Communication
    Replies: 1
    Last Post: 02-26-2009, 11:13 AM
  2. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  3. plzz suggest me some good online VC++ tuorials, i am a beginner
    By annamayya in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-18-2004, 05:56 AM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  5. Beginner needs help w/ran. nums. in arrays - URGENT!
    By madhouse199 in forum C++ Programming
    Replies: 3
    Last Post: 12-12-2001, 07:12 AM