Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,187 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,112 people online right now. Registration is fast and FREE... Join Now!




homework problem

 
Reply to this topicStart new topic

homework problem, Shift stored value of a character variable

Mdewman77
1 Aug, 2007 - 05:24 PM
Post #1

New D.I.C Head
*

Joined: 23 Jul, 2007
Posts: 4


My Contributions
Hi all,

Here is a homework problem I'm currently stuck half way through. The problem is to shift the stored value of five character variables (i.e. ABCDE becomes BCDEA, etc.). I have the call function but now I'm stuck on how to call it five times. Here is what I have:

void shift(char *p1, char *p2, char *p3, char *p4, char *p5)
{
char temp;
char p1 = 'A', p2 = 'B', p3 = 'C', p4 = 'D', p5 = 'E';
temp = *p1; *p1 = *p2; *p2 = *p3; *p3= *p4; *p4 = *p5; *p5 = temp;
}

This is under "callfunction.c". I believe I should have another file named main.c which calls it.

Any help?
User is offlineProfile CardPM
+Quote Post

BrainStew
RE: Homework Problem
2 Aug, 2007 - 06:02 AM
Post #2

D.I.C Head
**

Joined: 2 Aug, 2007
Posts: 149



Thanked: 1 times
My Contributions
I'm not exactly sure what your asking for, but if you don't have a main function you'll need that... so:
CODE

#include <iostream>
#include "callfunction.c"

int main(void)
{
   char a(A), b(B), c(C), d(D), e(E);

   for(int i(0); i<5; i++)
   {
       shift(&a, &b, &c, &d, &e);
   }

   return(0);
}


this would be in your main.cpp or main.c file, etc.

This post has been edited by BrainStew: 2 Aug, 2007 - 06:04 AM
User is offlineProfile CardPM
+Quote Post

k.sangeeth
RE: Homework Problem
2 Aug, 2007 - 08:39 PM
Post #3

D.I.C Head
**

Joined: 27 Jul, 2007
Posts: 61


My Contributions
If you need to shift all the characters ..
please increment each of them by one ..

CODE

int main()
{
char a='A',b='B';
shift(&a);
shift(&b);
}

void shift(char *a)
{
  *a = *a + 1;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 01:17AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month