Can anyone help me make sense from this?

This is a discussion on Can anyone help me make sense from this? within the C Programming forums, part of the General Programming Boards category; I have copied some code from the book to complie. Anyway, i am trying to copy this code that must ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Question Can anyone help me make sense from this?

    I have copied some code from the book to complie. Anyway, i am trying to copy this code that must use the function call void shift(&c1,&c2,&c3,&c4,&c5);. The function should shift letters ABCDE next BCDEA...etc...etc....

    This is what i had copied so far
    Code:
     #include<stdio.h>
    
    int main()
    {
    void shift(char *p1, char *p2, char *p3, char *p4, char *p5);
    void shift(&c1,&c2,&c3,&c4,&c5);
    return 0;
    }
    
    void shift(char *p1, char *p2, char *p3, char *p4, char *p5)
    {
        #define c1 ='A', c2 ='B', c3 ='C', c4 ='D', c5 ='E'
        #define END_INDEX 4
        int iCurrentShift = 0, iCurrentCharIndex = 0 ;
        char cFirstLetter ; 
    
        for( iCurrentShift = 1 ; iCurrentShift <= iShiftCnt ; iCurrentShift++) 
    
        {
            cFirstLetter = letter[ 0 ];  /* save the first as we're moving something in there */
            for( iCurrentCharIndex = BEGIN_INDEX ;  /*if BEGIN_INDEX = 0 & its equal to currentcharindex then goto next statement*/
                    iCurrentCharIndex <= END_INDEX - 1;
                        iCurrentCharIndex++)
            {
                letter[ iCurrentCharIndex ] = letter[ iCurrentCharIndex + 1];
            } /* end for icurrentcharindex */
     
            letter[END_INDEX ] = cFirstLetter ;
        } /* end for icurrentshift */
    } /* end function */
    what have i done wrong?
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  2. #2
    Registered User
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    212
    Code:
    void shift(char *p1, char *p2, char *p3, char *p4, char *p5);
    The are declarations so they go be for the main function.


    void shift(&c1,&c2,&c3,&c4,&c5);

    DO NOT use the void part when calling the function just do this "shift(&c1,&c2,&c3,&c4,&c5);"


    Code:
    void shift(char *p1, char *p2, char *p3, char *p4, char *p5)
    {
        #define c1 ='A', c2 ='B', c3 ='C', c4 ='D', c5 ='E' 
    ...
    This is a definition they may go before or after the main function (simple programs). If they go after you need a declaration before the main func.


    [EDIT]

    Just noticed something else, in the definition of shift, you have #define c1='A'... this is wrong, delete that, and in the main function add this line

    char c1='A', c2='B', c3 ='C', c4 ='D', c5 ='E' ;

    Then move the other #define's to the start of the program normally just after the #include's

    [/EDIT]
    Last edited by kwigibo; 07-23-2002 at 08:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does this even remotely make sense
    By hckr83 in forum C Programming
    Replies: 6
    Last Post: 12-23-2005, 05:02 PM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  3. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 12:50 PM
  4. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 03:16 PM
  5. Foreigners don't make sense
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-25-2002, 03:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21