Thread: char arrays, pointers, etc, could use help badly

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    155

    char arrays, pointers, etc, could use help badly

    Code:
    #include <iostream.h>
    using namespace std;
    
    void displayDay(char *ptr);
    void displayDayAddress(char *ptr);
    
    int main(){
    	char *days[] = {"Sunday",
    					"Monday",
    					"Tuesday",
    					"Wednesday",
    					"Thursday",
    					"Friday",
    					"Saturday"};     //array of char pointers
    	int selectedDay;
    	char *ptr;       //character pointer
    	
    	cout << "OUTPUT FOR PROBLEM #6a and #6b: " << endl;
    	cout << "What day is it today? (1 - 7): ";
    	cin >> selectedDay;
    	ptr = days[selectedDay - 1];        //store address of the given array element in ptr
    	displayDay(ptr);
    	
    	cout << "\n\nOUTPUT FOR PROBLEM #6c: " << endl;
    	cout << "This day's address begins at: ";
    	displayDayAddress(ptr);
    	
        return 0;
    } //end int main
    
    
    void displayDay(char *ptr){
    	cout << "Today's day is " << ptr;
    	 
    } //end void displayDay
    
    
    void displayDayAddress(char *ptr){
    	cout << &ptr;
    }
    For some reason I can't do what I want to do. What I want to do:

    -Send into a function that large *char array of months, and an int
    -In that function, the user will input a number into this int
    -That day is called from the function. For instance, entering 2 will display Monday

    -Then I need to make another function that outputs the address of the first character of the day inputted.


    However, I can't get this to work right! I can't pass the values correctly so the majority of it is in main!! I could really use some assistance
    Last edited by Nakeerb; 10-11-2002 at 09:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM