Character shift program need some assistance

This is a discussion on Character shift program need some assistance within the C Programming forums, part of the General Programming Boards category; I am trying to write this shift function to print 5 times with a result of bcdea, cdeab, deabc, eabcd, ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    51

    Character shift program need some assistance

    I am trying to write this shift function to print 5 times with a result of bcdea, cdeab, deabc, eabcd, abcde,,, I cannot get the function to work. Please point out my error... thanks in advance...


    Code:
    #include <stdio.h>
    
    int main()
    char shift(char *p1, char *p2, char *p3, char *p4, char *p5);
    {
    	char c1='A',c2='B',c3='C',c4='D',c5='E';
    	int count=0;
    	printf("%c%c%c%c%c\n",c1,c2,c3,c4,c5); 
    	while(count <= 4)
    	{
    		shift(&c1,&c2,&c3,&c4,&c5);
    		printf("%c%c%c%c%c\n",c1,c2,c3,c4,c5);
    		count++;
    	}
    	return 0;
    }
    
    char shift(char *p1, char *p2, char *p3, char *p4, char *p5)
    {
    	char temp;
    	temp = *p5;
    	*p5 = *p4;
    	*p4 = *p3;
    	*p3 = *p2;
    	*p2 = *p1;
    	*p1 = temp;
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The program works fine if you just move the declaration of shift one line up ( or down ).
    Kurt
    EDIT: BTW if you declare shift to return a char you should return something.
    Last edited by ZuK; 04-15-2006 at 01:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Gradebook Program - Small Problem, Need Assistance
    By CaitlynCraft in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 08:51 PM
  3. Character handling help
    By vandalay in forum C Programming
    Replies: 18
    Last Post: 03-29-2004, 04:32 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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