Inputting data with strings, and declaring variables for them

S

snow.carriers

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/2005/senior/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.
 
B

Bob Hairgrove

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/2005/senior/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.
 
S

snow.carriers

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...
 
F

Frank Schmidt

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/d...en-us/vccore98/HTML/_crt_fgets.2c_.fgetws.asp

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

Noclambulist

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 )
{
.........
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top