Raised This Month: $ Target: $400
 0% 

Solved Reading File:Array index is out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJPlaya
Senior Member
Join Date: Nov 2014
Location: Germany
Old 07-11-2017 , 15:12   Reading File:Array index is out of bounds
Reply With Quote #1

I dont get the Problem here, its simply not reading the Textfile

-The File containts various Types of special Characters like . / _ ( ) = < > \ ' ! - : $
-The File is not utf-8 (to be sure i tested ansi and unicode)
Code:
char sPath[PLATFORM_MAX_PATH];
char sFilter[32][256];
int iFilterCount;

public void OnMapStart() 
{
	iFilterCount = 0;
	File bdc = OpenFile(sPath, "r");
	while(!bdc.EndOfFile())
	{
		bdc.ReadLine(sFilter[iFilterCount], 256); //Error: Array index is out of bounds
		iFilterCount++;
	}
	delete bdc;
}
I appreciate any Help
__________________
My biggest Projects: Kigen AC Redux, Forlix Floodcheck Redux

Last edited by DJPlaya; 07-12-2017 at 16:54.
DJPlaya is offline
Send a message via Skype™ to DJPlaya
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-11-2017 , 17:22   Re: Reading File:Array index is out of bounds
Reply With Quote #2

Are you setting sPath?

Edit: This belongs in the scripting section.
__________________

Last edited by Neuro Toxin; 07-11-2017 at 17:23.
Neuro Toxin is offline
Totenfluch
AlliedModders Donor
Join Date: Jan 2012
Location: Germany
Old 07-11-2017 , 19:48   Re: Reading File:Array index is out of bounds
Reply With Quote #3

Quote:
char sFilter[32][256];
On line 33 your array will be out of bounds..
__________________
Notable Projects:
Event Item Spawner | Scissors, Rock, Paper for ZephStore
tVip | Smart Link Remover
PLG & GGC - CS:GO Roleplay

and countless more...

I can make a helicopter shoot missles if you want me to...
Totenfluch is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 07-12-2017 , 00:39   Re: Reading File:Array index is out of bounds
Reply With Quote #4

If you're reading a file of an indeterminate length, you need to use a dynamic data structure to grow as needed. An ArrayList will do you well.

PHP Code:
char sPath[PLATFORM_MAX_PATH];
ArrayList list;

public 
void OnMapStart() 
{
    list = new 
ArrayList(256); // 256 is block size
    
    
File bdc OpenFile(sPath"r");
    
    
char temp[256]; // declare temp string
    
    
while(!bdc.EndOfFile())
    {
        
bdc.ReadLine(tempsizeof(temp)); // read string into temp var
        
list.PushString(temp); // push string to list
    
}
    
    
delete bdc;


Last edited by headline; 07-12-2017 at 00:40.
headline is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 07-12-2017 , 01:40   Re: Reading File:Array index is out of bounds
Reply With Quote #5

Or interpret line by line if possible to avoid storing large amounts of unrequired memory.
__________________
Neuro Toxin is offline
DJPlaya
Senior Member
Join Date: Nov 2014
Location: Germany
Old 07-12-2017 , 16:44   Re: Reading File:Array index is out of bounds
Reply With Quote #6

Quote:
Originally Posted by Headline View Post
If you're reading a file of an indeterminate length, you need to use a dynamic data structure to grow as needed. An ArrayList will do you well.
Thx this seems to be the very best Solution
__________________
My biggest Projects: Kigen AC Redux, Forlix Floodcheck Redux
DJPlaya is offline
Send a message via Skype™ to DJPlaya
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 06:15.


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