470,815 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Inputting data with strings, and declaring variables for them

http://www.rafb.net/paste/results/fTQgRW16.html
Here's my program so far. This is what I'm trying to do:
http://contest-cemc.uwaterloo.ca/ccc...nior/phone.pdf
So far it works fine. The only problem is that I'm not sure how to
input data, s1, into the program. The second thing that I'm not sure
how to input the variable into the function.

The code:

strcpy(line, "88-SNOW-5555");

That's where the input will go. However, as you can see, I have five
inputs. I know that I should use a for loop or something for those, but
I don't know how I would incorporate it. Does anyone know? I know this
is relatively simple in java.

PS: I'm using an old borland compiler, so new methods in C++ won't
work, such as std::string, declaring a regular string, etc.

Thanks.

Feb 26 '06 #1
4 1797
On 26 Feb 2006 12:21:50 -0800, sn***********@gmail.com wrote:
http://www.rafb.net/paste/results/fTQgRW16.html
Here's my program so far. This is what I'm trying to do:
http://contest-cemc.uwaterloo.ca/ccc...nior/phone.pdf
So far it works fine. The only problem is that I'm not sure how to
input data, s1, into the program. The second thing that I'm not sure
how to input the variable into the function.

The code:

strcpy(line, "88-SNOW-5555");

That's where the input will go. However, as you can see, I have five
inputs. I know that I should use a for loop or something for those, but
I don't know how I would incorporate it. Does anyone know? I know this
is relatively simple in java.

PS: I'm using an old borland compiler, so new methods in C++ won't
work, such as std::string, declaring a regular string, etc.

Thanks.


How old? You can download the Borland command-line compiler for free
.... the same one which was used in Borland C++ Builder ver. 5. That
has a usable STL implementation, although it has some bugs
(std::getline doesn't work as advertised, for example).

Looks like "Input will be contained in the file s1.in" ... they don't
say where the file's path is located, though.

If you can't use a more up-to-date compiler which has an
implementation of the STL, you will have to open and read in the file
using either the C runtime functions or platform-specific functions.

--
Bob Hairgrove
No**********@Home.com
Feb 26 '06 #2
Tubo C++ 4.5
However I know that there is still a way to get data inside the program
and to use a variable for each line. I could use Dev C++, but I don't
have much time to learn the new methods...

Feb 26 '06 #3

<sn***********@gmail.com> schrieb im Newsbeitrag
news:11*********************@u72g2000cwu.googlegro ups.com...
Tubo C++ 4.5
However I know that there is still a way to get data inside the program
and to use a variable for each line. I could use Dev C++, but I don't
have much time to learn the new methods...


for your former ifstream sample: (ifstream fout("s1.in")) ... maybe...

char data[256];
fout.getline(data, 256);

and rename fout to fin... :P
else the mentioned c-style functions... an example you can find on

http://msdn.microsoft.com/library/de...2c_.fgetws.asp

kinda down the page. a "int n = atoi(line);" would then help to read the
number on the first line.


Feb 26 '06 #4
How about devcpp? I think it fine;

Do you want get input data from file or prompt?
if the latter one, try

while ( cin >> data )
{
.........
}

Feb 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by Troll | last post: by
6 posts views Thread by Mark A. Sam | last post: by
7 posts views Thread by fakeprogress | last post: by
5 posts views Thread by Chris | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.