Raised This Month: $51 Target: $400
 12% 

reading file help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
daniel46
Senior Member
Join Date: Dec 2011
Old 12-03-2013 , 16:12   reading file help
Reply With Quote #1

so i have this code

Code:
new Song[ 64 ][ 10 ]
public read_sample()
{
	// get path from amxx config dir
	new path[32]
	get_configsdir(path, charsmax(path)) // now config dir in path stored
	
	// store file dir in path
	formatex(path, charsmax(path), "%s/medialist.ini", path) // store complette path to file
	
	// check if file exists
	if (file_exists(path))
	{
		// do stuff
		
		// if u don't know how much lines have the file
		// use while state, i = integer, sz = string
		new szData[33], szName[32], szFileName[64], iTextLength, iLine
		
		// reads line from file. returns index of next line or 0 when end of file is reached.
		while (read_file(path, iLine, szData, charsmax(szData), iTextLength) != 0)
		{
			// check if more lines in the file as g_szSample[] can store...
			if (iLine > 10)
				break // this stop the while
			
			// found what on the line
			parse(szData, szName, charsmax(szName), szFileName , charsmax(szFileName) )
			
			
			// now u can check, what is stored in szSample
			
			// comment or blank line = continue, read a new line!
			if (szName[0] == ';' || !szName[0])
			{
				// increase the line by 1
				iLine++
				continue
			}
			
			// if not comment or blank line
			// so new can new work on it
			
			// store the text in a golbal string var (g_sz)
			Song[iLine] = szName[iLine]
			szFileName[iLine] = File[iLine];
			
			// increase the line by 1
			iLine++
		}
	}
}
and when i try to realy use it in my menu its wont write the string
daniel46 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-05-2013 , 02:37   Re: reading file help
Reply With Quote #2

Several things are wrong with your code:
  1. Don't use read_file(), use fopen(), fgets(), fclose()
  2. The variable "Song" is for 64 strings each of length 9
  3. Don't assign strings to strings with an equal sign
  4. szName should not be index when you do want to assign the string to another variable
  5. The variable "File" does not exist.
  6. You should not use "iLine" to index any arrays. Though, you won't have this issue when you do number 1.

And, before you ask, search for examples using the newer file functions. One example is in my signature (Hint: It's not the really big complicated one).
__________________
fysiks 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 10:01.


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