fwrite
#1

I'm trying to create and write to files. I'm getting errors on the line im using fwrite for. I'm not sure if im doing the handle part of it right. This is what is on the line.
Quote:

fwrite(testfile.txt, "This is test text.\r\n");

I'm not sure what the handle should be. Right now I have it as the name of the file. Help would be appreciated.
Reply
#2

Try opening the file first. Something like:
pawn Код:
new File:test = fopen("/testfile.txt", io_write);
    fwrite(test, "This is test text.\r\n");
Reply
#3

alright now here what i have.

Quote:

24 if(!fexist("testfile.txt"))
25 new File:test = fopen("/testfile.txt", io_write);
26 fwrite(test, "This is test text.\r\n");
27 fclose(test);

and here's the errors/warnings im getting for that.

Quote:

(25) : error 003: declaration of a local variable must appear in a compound block
(25) : warning 221: label name "File" shadows tag name
(25) : error 017: undefined symbol "test"
(26) : error 017: undefined symbol "test"
(27) : error 017: undefined symbol "test"
(25) : warning 203: symbol is never used: "File"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Reply
#4

alright so i figured out my idiotic problem... i forgot the {}'s it should look like this:

Quote:

if(!fexist("testfile.txt"))
{
new File:test = fopen("/testfile.txt", io_write);
fwrite(test, "This is test text.\r\n");
fclose(test);
}

Reply
#5

Quote:
Originally Posted by Dennis_Smith
Посмотреть сообщение
alright so i figured out my idiotic problem... i forgot the {}'s it should look like this:
So, finally, does it work or ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)