Thread: help using pointers

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    2

    help using pointers

    i have to write a program to rotate the elements of an array a specified number of places input by the user, with these specifications:
    1. A positive number indicates a rotation to the right
    2. A negative number indicates a rotation to the left
    3. Use only pointer notation (not array notation) in the functions other than main.
    4. Do not declare additional space to hold an array outside of main; in other words, rotate the array "in place"

    Does anyone know how to go about adding into this partial code to make this work?

    Code:
    #define  SIZE  10
    
    /* function prototypes go here */
    int main()
    {
       int a[SIZE] = {23, -3, 6, 19, 88, -5, 7, 34, -101, 88};
       int places;
    
       printf("Original array:\n");
       showArray(a, SIZE);
       printf("\n\nRotate how many places (+/- for right/left)? ");
       scanf("%d", &places);
       rotate(a, SIZE, places);
       printf("\nRotated array:\n");
       showArray(a, SIZE);
    
       printf("\n\n");
       system("pause");
       return 0;
    }

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Yes, by implementing the rotate() and showArray() functions.

    Have a go at them, and if you run into trouble, post your errors/problem, and the forum will lend a hand.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM