473,395 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

manipulate string c++

2
Expand|Select|Wrap|Line Numbers
  1. void addition::print_output()
  2. {
  3.     cout << "Enter value : ";
  4.     getline(cin,store);
  5. }
-----------------------------------------------------------------------

here my problem,
for e.g : if user enter value like this
123,456,789,764,345 or 123456789764345
then i would like to convert to this for e.g :
block[0] = 345
block[1] = 764
block[2] = 789
block[3] = 456
block[4] = 123

i just don't know how to start write this function.
-----------------------------------------------------------------------
my private in class :
Expand|Select|Wrap|Line Numbers
  1.     private: 
  2.         string store;
  3.         int block[];
-----------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. int addition::manipulate()
  2. {
  3.     // i guess it would involve if..else and for loop.
  4. }
-----------------------------------------------------------------------

i just need an example.. :(
please help.
thank you.
Aug 20 '07 #1
3 2286
Ganon11
3,652 Expert 2GB
Well, you need to have a few things:

1) I assume the length of the number that the user enters can vary. If so, you need a way to determine how many digits there are in the input number. This total, divided by 3, is how many slots your array will require.

2) You need a way of seperating each 3-digit sequence from the rest of the number. Use modulus division to get the sequence, then integer division to truncate the number.

3) A variable to keep track of which array slot is being filled. You could use the index of a for loop, but the nature of your problem suggests a while loop. In this case, you need a seperate variable, starting at 0 and incrementing to the max number needed.

If the length does not vary (see point 1), then the problem is simple! This means that the user will always enter a 15 digit number, you will always need an array of length 5, you will execute step 2 exactly 5 times, etc. etc.
Aug 20 '07 #2
redx
2
thanks for your reply.
i know how to do step one,
store.length().
then divide 3..

but, i stuck in step 2. i dont know how to seperate ?

sory.. and thanks again.
Aug 21 '07 #3
hariharanmca
1,977 1GB
thanks for your reply.
i know how to do step one,
store.length().
then divide 3..

but, i stuck in step 2. i dont know how to seperate ?

sory.. and thanks again.
seperate string

I think this page will guid you
Aug 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Paul | last post by:
This method: static void swap(int a, int b) { int c = a; a = b; b = c; } does not swap the values of a and b over. It doesn't work for String variables either. However the following method...
14
by: Chris | last post by:
I heard that strings are immutable, but isn't there regardless a way to manipulate a string? I have a string that looks like this: a = '0123456789' But I want it to look like this: a = '0 - 2 -...
5
by: Greg Scharlemann | last post by:
If I have a date that looks like: 2005-12-07 10:10:00 How could I manipulate it in php to say "Dec, 07, 2005"? I can separate the string at the space, but don't know where to go from...
1
by: tom | last post by:
Hi, I am a newbie and have a simple question? I have a aspx file and on the form I have a user control which is my header and has some images. Now for various pages I need to load different...
4
by: G | last post by:
Hello, Does anyone have any code handy which will take a certain part of a string and save it as an independant string? For example: "Thank you for visiting our web site. You were sent...
0
by: Bart | last post by:
Hi, i want to programmatically manipulate the property 'Name' of a ControlParameter inside a InsertParameters tag. This the aspx code: ------------------ <asp:SqlDataSource...
1
by: Imnew2c | last post by:
need help with logic of a pgm... pgm is to print the following output... This computer generated string contains ___letters:,____ A,_____B, ....._____Z. This is the output. The blanks are...
5
by: sachin770 | last post by:
i am a beginner .can you give me idea how we can manipulate "LARGE" integers (positive or negative) of arbitrary size. These integers could be greater than MAX_INT or smaller than MIN_INT. using...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.