Thread: Accessing a colum in an Array

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    32

    Accessing a colum in an Array

    I give up and am asking for help here. Im playing around with arrays and trying to get characters from within the array.
    Code:
    int main()
    {
    	char array[20] = "1,2,3,4,5,6,7,8,9,0";
    	char ch[20];
    	int i;
    
    	for(i = 3; i < 7; i++)
    	{
    	        ch[20] = ch[20] + array[i];
    	}
    
    	cout << ch;
    	cout << endl;
    	return 0;
    }
    This will spit out a bunch of strange symbols and then the ",2,3,4,5". What am I doing wrong this is driving me nuts.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    What is it that you want it to exactly print?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    32
    With this array I want to try and print only the characters ",2,3,4,5". My loop however first prints a bunch of junk and then will print ",2,3,4,5" so I take it that I am not doing it the correct way.
    Last edited by Zalbik; 11-23-2002 at 03:14 PM.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    here ya go
    Code:
    #include <iostream>
    #include <conio.h> // for my compiler
    
    using namespace std;
    
    int main()
    {
    	int array[10] = {1,2,3,4,5,6,7,8,9,0};
    	int i;
    
    	for(i = 1; i <=4; i++)
    	{
    	      cout << array[i];  
    	}
    	getch(); // for my compiler	
        return 0;
    }
    hope this helps

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    32
    Hey that works...thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  2. accessing user entered array elements by index?
    By richdb in forum C Programming
    Replies: 10
    Last Post: 04-08-2006, 11:10 AM
  3. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  4. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  5. Object array. Probelm accessing methods
    By Bean in forum C++ Programming
    Replies: 4
    Last Post: 05-03-2004, 11:22 AM