Reputation: 11
I have to develop a project where I must read data from a .csv file like this:
10,12.1
15,25.6
15,25.1
...
so I tried to read as follows:
.data
file: .asciiz "/home/gilson/Documents/test.csv"
.word 0
buffer: .space 4
.text
main:
#open file
li $v0, 13
la $a0, file
add $a1, $zero, $zero
add $a2, $zero, $zero
syscall
add $s0, $v0, $zero
#read 4 bytes from file
li $v0, 14
add $a0, $s0, $zero
la $a1, buffer
li $a2, 4
syscall
#print
li $v0, 1
lw $a0, buffer
syscall
done:
li $v0, 16
add $a0, $s0, $zero
syscall
exit:
li $v0, 10
syscall
and I had the following output:
824979505
-- program is finished running --
so I changed the print syscall to print string and the output was:
...
li $v0, 4
la $a0, buffer
syscall
...
10,1
as I could see he is reading from the file in character, not in number format. I would like to know if there is a way to directly read the numbers or do I have to necessarily use some procedure to convert from char to int?
Upvotes: 1
Views: 779
Reputation: 351
Numbers which you are reading from the files will be in text format. You need to convert(typecast) them from text to number.
Upvotes: 0