-
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;
}
-
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.
-
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
-
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.