Raised This Month: $ Target: $400
 0% 

Solved File cannot be read correctly (only reads 1 character)


Post New Thread Reply   
 
Thread Tools Display Modes
EfeDursun125
Senior Member
Join Date: Feb 2019
Location: Turkey
Old 04-11-2022 , 13:27   Re: File cannot be read correctly (only reads 1 character)
Reply With Quote #11

Quote:
Originally Posted by Bacardi View Post
ok, I maybe found your two problems.

When you save file,
you not set NULL terminate on WriteString header.author
- Next time when you read string, it read long as next NULL appear, mostly from your first waypoint data with value 0.
Or if 0 value not appear first, read whole 32 bytes.
*edit
- When not set NULL fp.WriteString(header.author, false);, it add Horizontal Tab (0x09) or it is random byte :S


When you load file,
you ReadString, with size of header.author [32 bytes]
- You read author name with bunch of data same time.
To avoid this problem is set NULL terminate into strings and ReadString till first NULL terminate comes.


Code:
stock void WaypointLoad()
...
    File fp = OpenFile(filepath, "r");
...
    // read about the file and author
    WaypointHeader header;
    fp.ReadString(header.author, sizeof(header.author), -1);
    fp.Read(header.pointNumber, 1, 1);
...



stock void WaypointSave()
...
    File fp = OpenFile(filepath, "w");
...
    // write about the file and author
    fp.WriteString(header.author, true);
...
I edit those two lines.



If it still not work, then order of loading and save data maybe not work correctly...
name is loaded correctly but other data isn't

PrintHintTextToAll("Waypoint file author: %s\nWaypoints found: %s", header.author, m_waypointNumber);

m_waypointNumber is empty space

EDIT: when waypoint file readed, this happens: https://steamcommunity.com/sharedfil...?id=2792922012
__________________
CS 1.6 E-BOT (Best Bot For Zombie Plague): https://github.com/EfeDursun125/CS-EBOT

Last edited by EfeDursun125; 04-11-2022 at 13:35.
EfeDursun125 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-11-2022 , 13:40   Re: File cannot be read correctly (only reads 1 character)
Reply With Quote #12

Can you post saved waypoint file, including many waypoints ?
__________________
Do not Private Message @me

Last edited by Bacardi; 04-11-2022 at 13:41.
Bacardi is offline
EfeDursun125
Senior Member
Join Date: Feb 2019
Location: Turkey
Old 04-11-2022 , 13:50   Re: File cannot be read correctly (only reads 1 character)
Reply With Quote #13

Quote:
Originally Posted by Bacardi View Post
Can you post saved waypoint file, including many waypoints ?
EDIT: fixed with C++ style write/read now everything is written as binary even name and it can read the all data now, have 4 warnings but its fine.
Attached Files
File Type: inc waypoints.inc (15.5 KB, 11 views)
__________________
CS 1.6 E-BOT (Best Bot For Zombie Plague): https://github.com/EfeDursun125/CS-EBOT

Last edited by EfeDursun125; 04-11-2022 at 19:10.
EfeDursun125 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-11-2022 , 19:21   Re: File cannot be read correctly (only reads 1 character)
Reply With Quote #14

Neat.
Bacardi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode