fwrite help
#1

Hi im trying to make a system that i type /leaveanote [TEXT HERE]. And it will save what you have type into a .txt but i get 1 error here is my command:

Код:
	if(strcmp(cmd, "/leaveanote", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] >= 1337)
			{
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /leaveanote [Note(TEXT)]");
					return 1;
				}
				new note;
				note = strvalEx(tmp);
				{
					new File:log = fopen("/adminnotes.txt", io_write);
				    fwrite(log, note);// this is line 27006 the line with the error
    				fclose(log);
					format(string, sizeof(string), "   You have left the note %s", note);
					SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
				}
			}
		}
		return 1;
	}
and here is my error:
Код:
C:\Users\Ryan\Desktop\World Wide RolePlay\gamemodes\WWRP.pwn(27006) : error 035: argument type mismatch (argument 2)
Reply
#2

fwrite writes text so u must convert value to text
pawn Код:
new vstr[64];
valstr(vstr,note);
fwrite(log, vstr);// this is line 27006 the line with the error
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
fwrite writes text so u must convert value to text
pawn Код:
new vstr[64];
valstr(vstr,note);
fwrite(log, vstr);// this is line 27006 the line with the error
well i try what you said here is the command:
Код:
	if(strcmp(cmd, "/leaveanote", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] >= 1337)
			{
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /leaveanote [Note(TEXT)]");
					return 1;
				}
				new vstr[64];
				new note;
				note = strvalEx(tmp);
				{
					new File:log = fopen("/adminnotes.txt", io_write);
					valstr(vstr,note);
					fwrite(log, vstr);
    				fclose(log);
					format(string, sizeof(string), "   You have left the note %s", vstr);
					SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
				}
			}
		}
		return 1;
	}
and all it dose when i have a look in the .txt file it puts a 0 not the text i type in. how do i fix this.
Reply
#4

pawn Код:
if( strcmp( cmdtext, "/leavenote", true ) == 0 )
{
   if( PlayerInfo[ playerid ][ pAdmin ] >= 1337 )
   {
      new
         string[ 128 ],
         File: open = fopen( "adminnotes.txt", io_append );
      ;

      format( string, sizeof( string ), "%s", cmdtext[ 11 ] );
      fwrite( open, string );
      fclose( open );
   }
   return 1;
}
This is just the basics of what you need, and doesn't need strtok!

Please note that this is just a sample. You will need to make sure the file exists before writing to it ( in this case ). I would also suggest adding a check to make sure the file is valid.
Reply
#5

i still can't get this to work please help
Reply
#6

Explain the problem you are having in-depth. I cannot magically fix your problem with no background information.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)