All my inputs only work if i put a full stop at the end of them. Is there anyway to make it so i can just input something and press enter. Also those inputs can only be one word so i can't make and spaces.
Thanks for the help.
I think that works but i need to say if the file doesn't exist create it and now do something else e.g.
If(file_does_not_exist)
/*do something*/
else
/*extract file contents*/
right now it is creating the file but can't read anything because it's empty so i need to skip that if the file...
I have my program reading in data from a file but i want it to create a file if the given filename does not exist.
read(File),
open(File, read, S),
read(S, X),
close(S),
doStuff(X).
I have found that in the open line I should be able to have | open(File, readwrite, S),
but that doesn't work...
I am using swi-prolog and I can't get formatted io to work.
I have been taught: fmt_read() and fmt_write()
are those correct?
Why isn't it working?
Thanks
Ok I haven't really found any clear way of doing an If statement in PROLOG. I want to read a word into a variable and then run either one of 2 functions if the answer is yes or no.
Bare in mind I am very new to PROLOG so here is what I have:
read(Var),
yesVar :-
Var="Yes", yesFunction(Var)...
I am simply trying to set-up my prolog environment and ii have a simply program.
write(a).
that's it...
It always tells me "No permission to modify static procedure `write/1'"
Also does the same for read. As i have never used prolog is it something wrong with how i have set it up or do i need...
Is there a set length you of line you can put code on?
Eventually if a line goes too long i get an error and it clearly just stops mid line and outputs a random error.
It's really annoying when i want a line of text on one line
so is there a way i can say print this on one line:
print *, 'This...
hmm still the same problem :S
Changed the read and writes like you said but exactly the same.
Maybe the full code will help a bit more
CHARACTER*20 new Animal
CHARACTER*50 newQuestion
read *, newAnimal
read '(A100)', newQuestion
OPEN(7, fileName, ACCESS='APPEND')
WRITE(7, '(A100)')...
If i have a text file say:
"dog cat mouse elephant"
and i want to read those into an char array the reader always just reads dog and then moves to a new line.
I don't know how many 'animals' will be in the text file so i can't just
read (7,*) animal(1), animal(2) etc, but i do know there isn't...
hmm that seems to work kind of. IT reads the line into the txt file but the last word is always added to the next line.
So if the newQuestion is: "How are you?"
it will be added
How are
you?
thoughts?
Thanks for the help
I thought calling a function seemed easy enough until i tried to write one.
I though it was as easy as:
program test
testFunction()
end program test
FUNCTION testFunction()
print *, "Hello World"
END
EDIT:
ok so why does below work. I just want a function that makes my code cleaning. No...
Can someone tell me how to write whole lines to text files. Here is what I have tried but got just the first word 'do'.
is has opened unit 7 as append for an existing file
CHARACTER*50 newQuestion
read *, newQuestion
write(7, '(A)') newQuestion
say i type "do you want to?" it only adds the 'do'...
Well I have it reading in a whole question with the first (A) that was posted.
The I have some possible answers like Horse:Dog:Cat
So i would get them one by one and add them to a character string array.
Don't have to tell me how to do the whole thing just teach me how to read until a : then do...
I have tried everything to get a simple bit of code to work but nothing has worked.
pseudocode:
get user answer (yes/no)
if answer = yes
print yes
I always get the same error "Cannot assign to a named constant"
i have tried
--
t = LGT(answer, 'yes')
IF(t)
--
if(answer .eq. 'yes)
--...
Thanks that works perfect.
How would I go about reading until a ":" is found?
and does fortran have an if(!eof) if not end of file statement i can use?
Sorry but I am just starting and am having a bit of trouble.
Thanks
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.