Computing.Net > Forums > Programming > string input into an array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

string input into an array

Reply to Message Icon

Name: Rich
Date: September 6, 2003 at 20:29:54 Pacific
OS: 2000
CPU/Ram: C++
Comment:

I'm trying to input a string (123213) and put it into a single dimension array. I'm declaring the array to size 20 which should be big enough fo anything I will need. Anything that you guys can say on this will b appresiated. Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: September 6, 2003 at 20:36:02 Pacific
Reply:

How do you want to do this?
char or _basicstring?

if you use char it will already be in an array:

char theWords[20];


Chi Happens


0

Response Number 2
Name: Rich
Date: September 6, 2003 at 20:42:19 Pacific
Reply:

I'm wanting to use a string of ints.


0

Response Number 3
Name: Chi Happens
Date: September 6, 2003 at 21:16:19 Pacific
Reply:

ok, so
char theIntegers[20];

am i missing something?


0

Response Number 4
Name: Rich
Date: September 6, 2003 at 21:25:35 Pacific
Reply:

I'm trying not to use a char, i'd rather use an int. I am going to have to do some operations with the numbers. I have tried to load it in as a char and do an atoi command to change it into an int, but it gives me the ASCII value of the number instead of the number (ie. '3' = 51). Is there a way to convert the ASCII back to its original value? Thanks


0

Response Number 5
Name: Chi Happens
Date: September 6, 2003 at 21:28:01 Pacific
Reply:

wtf!!!

man, this forum is pissing me off tonight. it keeps jumping back and forth. grrr (I HATE THE JAVASCRIPT ADS!!!!)

Anyhow, try this:

char *str = "12345.67";
n = atoi(str);
cout n;

Chi Happens


0

Related Posts

See More



Response Number 6
Name: Rich
Date: September 6, 2003 at 22:02:16 Pacific
Reply:

Thats getting me in the right direction (I think).
Thanks for your help.


0

Response Number 7
Name: Chi Happens
Date: September 6, 2003 at 22:05:01 Pacific
Reply:

this works correctly in vc++ as well as borland c++ (atoi worked right in borland but not in vc++...thanks bill)

#include <conio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void)
{
     int n, step = 1, t;
     bool done = false;
     int nums[20];
     char *str = "12345";
     n = atoi(str);
     
     for(t=0l;t<20;t++)
          nums[t] = 0;

     cout << "convert: " << n << endl;
     while(!done)
     {
          if(n % 10 == 0 && n == 0)
               done = true;
          else
          {
               nums[20-step] = (n % 10);
               n = n/10;
               step++;
          }
     }

     cout << "array: ";
     for(t=21-step;t<20;t++)
          cout << nums[t];
     getch();
     return 0;
}

Chi Happens


0

Sponsored Link
Ads by Google
Reply to Message Icon

VB.net Under Windows 98 window based appilcations...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: string input into an array

read data from a file into an array www.computing.net/answers/programming/read-data-from-a-file-into-an-array/11140.html

Perl, compare lines in an array www.computing.net/answers/programming/perl-compare-lines-in-an-array/14724.html

Sparc Language, array www.computing.net/answers/programming/sparc-language-array/10222.html