how to fill multiple array locations with one input

This is a discussion on how to fill multiple array locations with one input within the C++ Programming forums, part of the General Programming Boards category; I am trying to fill an array with a large number using cin. What I would like to do it ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    28

    how to fill multiple array locations with one input

    I am trying to fill an array with a large number using cin. What I would like to do it take a number like 123,456,789 and put it into someArray[0] = 123, someArray[1] = 456, etc. Can this be done easily?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,941
    Can this be done easily?
    Probably. After all, it depends on what exactly you want to do. Are you trying to split by commas?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970

  4. #4
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    guess you could:

    1) Take the input as a character string instead of a number.
    2) Parse the character string.
    3) Convert string to an int before storing in the array.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    28
    Quote Originally Posted by laserlight
    Probably. After all, it depends on what exactly you want to do. Are you trying to split by commas?

    I need some way to seperate either by commas or seperate into 3 digit pieces after the fact.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    You could just remove all the non-digit characters from the string, then read in three characters at a time.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can you input a string in an array?
    By chizL in forum C Programming
    Replies: 2
    Last Post: 12-24-2007, 10:10 PM
  2. trying to read input into an array
    By trprince in forum C Programming
    Replies: 16
    Last Post: 11-17-2007, 05:20 PM
  3. input row of integers via scanf into an array...
    By noodles355 in forum C Programming
    Replies: 1
    Last Post: 11-20-2006, 09:12 AM
  4. Trying to fill an int array
    By boojus in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2003, 01:31 PM
  5. How to input multiple groups of data
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-14-2002, 09:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21