Re: Quick string question
fopen() will open the file.
fread() will read as many bytes as you specify, and not care at all what's in them. But if there are 255 bytes reserved for the string, and that length guaranteed to be in the file, then you can just read the 255 bytes. The string manipulation functions recognize the NUL.
Is it worth the space waste, though? Just store the length.
You shouldn't use any other function except perhaps fgetc() (reads exactly one byte) for binary files.
Re: Quick string question
if you have a string stored in chars how do you remove the end line identifier ("/n")
so if i read a text file and it returned the line "Fred smith/n" how do i remove the /n so the string reads "Fred smith" ?
... im new to c++ and cant for the life of me figure it out vb has functions like right left and trim etc
but c++ doesnt im really stuck
any help appreciated
cheers john ;)
Re: Quick string question
Why didn't you just start a new thread?
Anyway... You could overwrite the \n with the string ending character \0, or you could use strcpy() to copy the part of the string you want to another string assuming you're using "char str[]" type strings.
Re: Quick string question
wicked dude the /0 seems to be an option ill try it out :D
... i did start a new thread but it was much easier to explain what i needed to do in this thread .... i edited my existing thread to another because i hit problems reading values from a text file.
many thanks for your help ill let you know if it works ;)
Re: Quick string question
Halsafar, if the length will only ever be at max, 255, just write, in binary, the lenth as a BYTE at the beginning of the file.