getting the first char of a string from fgets?

Pixilang programming language
Post Reply
User avatar
AutumnCheney
Posts: 503
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

getting the first char of a string from fgets?

Post by AutumnCheney »

i'm reading a text file using fgets and storing each string into an INT8 container. something like this:

Code: Select all

file = fopen( "file.txt", "rb" )
temp_string = new( 1024, 1, INT8 )
length = 0

while 1 {
	length = fgets( temp_string, 1024, file )
	if ( length == -1 ) { break }
}

remove( temp_string )
fclose( file )
(sorry if the code wouldn't work, i'm manually typing it in based on my actual code)

now, i want to get the first character from the acquired string. but, i can't figure out how to do this. this is what i'm doing now:

Code: Select all

temp_string[ 0 ]
but, this seems to just get me the whole string, like the container is an array of strings

how can i get the first character? is there a better way than using an INT8 container?

thanks
my website: https://acheney.xyz

it features my music, sunvox content, and social media links!
ainegil
Posts: 168
Joined: Thu Sep 22, 2022 11:37 pm

Re: getting the first char of a string from fgets?

Post by ainegil »

did you try what

temp_string[ 0 ][ 0 ] is bringing up or

somecharacters = temp_string[ 0 ]
char = somecharacters[ 0 ]

?

I am not quite sure what you try to achieve and without testing I would also expect
that temp_string[ 0 ] is the first character
but then you are repeatedly writing into temp_string and the part when you check the
element is missing from your example so its hard to guess
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: getting the first char of a string from fgets?

Post by NightRadio »

temp_string[ 0 ] is the first character.
How did you check it?
Post Reply