Opening files.. etc help
#1

Код:
stock pAddGateKeys(name[], faction)
{
	new filestr[128],string[128];
    if(faction == 0) return 1;
    if(faction == 1){format(string,sizeof(string),"D-RP/Factions/LSPD_Keys.cfg");}
	new File:file = fopen(string,io_append);
	if (file)
	{
	  while(fread(file,filestr,sizeof(filestr)))
	  {
	  	if (strfind(filestr, name, true) != -1)
	  	{
	  	}
	  	else
	  	{
				format(string,128,"%s\r\n", name);
				fwrite(file,string);
	  	}
	  }
	}
	fclose(file);
	return 1;
}
well i am trying to add someone's name in a file if it doesn't exist in it but it doesnt work for some reason :S
Reply
#2

Sorry for bumping.. kinda in hurry
Reply
#3

if((file = fopen("file...i",io_append)))
Reply
#4

Quote:
Originally Posted by [ZDM
jumbo ]
if((file = fopen("file...i",io_append)))
What's the use of those brackets and only one "=" ?
Reply
#5

bump
Reply
#6

Quote:
Originally Posted by MafiaGuy™
bump
you're in a hurry ooooh people are in a hurry too idiots only can bump thats really bad of you don't act like a child!
Reply
#7

Код:
« Reply #3 on: May 15, 2010, 06:28:07 pm »
Код:
« Reply #4 on: Today at 08:41:14 am »
- You can bump your own topic after 12 hours. So don't bitch.

Reply
#8

please don't call me a bitch that wood make you something much more . kay?
Reply
#9

Oh dear... SAMP heroes fighting again


What happens when you execute that code?

The way I see it this:

Код:
  while(fread(file,filestr,sizeof(filestr)))
	  {
	  	if (strfind(filestr, name, true) != -1)
	  	{
	  	}
	  	else
	  	{
				format(string,128,"%s\r\n", name);
				fwrite(file,string);
	  	}
	  }
writes in quite a few names seeing that in each line you don't find "name" the else clause gets executed.

Is that the case or what happens - in which way does it not work correctly?
Reply
#10

wops.. i only meant to write them once..

when i execute the code i get no response..

Can i use "break" to break the loop ?

then:

Код:
stock pAddGateKeys(name[], faction)
{
	new filestr[128],string[128];
    if(faction == 0) return 1;
    if(faction == 1){format(string,sizeof(string),"D-RP/Factions/LSPD_Keys.cfg");}
	new File:file = fopen(string,io_append);
	if (file)
	{
	  while(fread(file,filestr,sizeof(filestr)))
	  {
	  	if (strfind(filestr, name, true) != -1)
	  	{
	  	}
	  	else
	  	{
				format(string,128,"%s\r\n", name);
				fwrite(file,string);
                break;

	  	}
	  }
	}
	fclose(file);
	return 1;
}
this code looks fucked up.. u have any other idea how to do it simplier or w/e ?
Reply


Forum Jump:


Users browsing this thread: