Help me with my code, I'm trying to get a specific integer from my .txt File
Author |
Message |
superben20
|
Posted: Wed Jan 06, 2016 10:12 pm Post subject: Help me with my code, I'm trying to get a specific integer from my .txt File |
|
|
What is it you are trying to achieve?
I want to be able to change 1 specific integer from a .txt File that only has specific integers on a different line.
What is the problem you are having?
I kept on having problems saying that there is an illegal character in the string, but I want an integer, not a string. I want 1 specific integer changed, not all of them.
Describe what you have tried to solve this problem
Looking the Web, and trying everything that was posted on the Compsci website, none of them worked well enough
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
var badges, Badge : int
var temp : array 1 .. 3 of int
open : badges, "Badges.txt", get
get : badges, temp(1)
close : badges
put : temp(1)
|
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Jeffmagma
|
Posted: Thu Jan 07, 2016 12:33 pm Post subject: Re: Help me with my code, I'm trying to get a specific integer from my .txt File |
|
|
Get them as strings, then use strintok to check if its the number you want |
|
|
|
|
![](images/spacer.gif) |
superben20
|
Posted: Thu Jan 07, 2016 1:58 pm Post subject: Re: Help me with my code, I'm trying to get a specific integer from my .txt File |
|
|
Ok, I tryed that, and it didn't work, it still says that there is an illegal character in the string:
var temp : array 1 .. 3 of int
var dummy : string
open : badges, "Badges.txt", get
for i : 1 .. 3
get : badges, dummy
if strintok(dummy) then
temp(i) := dummy
close : badges
open : badges, "Badges.txt", put
put : badges, temp(i)
end if
end for
This is the code that I have, I know that it doesn't work because the error of the illegal character in the string. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Thu Jan 07, 2016 2:10 pm Post subject: RE:Help me with my code, I\'m trying to get a specific integer from my .txt File |
|
|
strintok() only checks if the string can be converted to an integer. strint() does the actual conversion. |
|
|
|
|
![](images/spacer.gif) |
|
|