Thread: function shift

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    15

    Unhappy function shift

    Hi,

    Trying to make the letters ABCDE shift by one by calling in five times i.e. BCDEA, CDEAB, DEABC, EABCD, and ABCDE.

    Here's what I got and I know it's probably easy and I'm hosed up, but I'm an extreme noob at programming.

    Thanks in advance.

    Code:
    #include <stdio.h>
    
    int main(void)
    
    char  c1 = 'A', c2 = 'B', c3 = 'C', c4 = 'D', c5 = 'E';
    char *p1 = &c1, *p2 = &c2, *p3 = &c3, *p4 = &c4, *p5 = &c5;
    
    void shift(char *p1, char *p2, char *p3, char *p4, char *p5)
    {
    	shift(&c1, &c2, &c3, &c4, &c5);
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    The tutorials section is the one that you should be heading to right now. Your code is so messed up, that i think you should start right from a hello world program. Also, you dont specify what you want to do with the shifted letters. Your aren't shifting them in an array, so i really dont understand what you intend to do.
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    mattflick this is not complete proper programe. you got many error in it. pointing out the error,
    you havn't got the completed main fucntion.
    you cant assign a value for an pointer
    you cant use shift as an fucntion identifier as it is a inbuilt function identifier

    and the proper code for you problem

    Code:
    #include<stdio.h>
    
    void shiftchar(char *p1, char *p2, char *p3, char *p4, char *p5)
    {
        char temp;
        
        temp=*p1;
        *p1=*p2;
        *p2=*p3;
        *p3=*p4;
        *p4=*p5;
        *p5=temp;
    }
    
    int main()
    {
        char  c1 = 'A', c2 = 'B', c3 = 'C', c4 = 'D', c5 = 'E';
        int i;
        
        for(i=0;i<5;i++)
        {
            shiftchar(&c1,&c2,&c3,&c4,&c5);
            printf("%c %c %c %c %c\n",c1,c2,c3,c4,c5);
        }
        
        getchar();
    }
    /*my output
    B C D E A
    C D E A B
    D E A B C
    E A B C D
    A B C D E
    */
    and the better way of doing this using by string of char(strings)

    -ssharish2005
    Last edited by ssharish2005; 09-29-2005 at 03:12 AM.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    15
    Thanks so much for your help. I'm learning I just need more experience looking all the different types code for all there different applications. Thanks again for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM