Results 1 to 7 of 7

Thread: fgetarg and freadln

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    fgetarg and freadln

    Hi all,

    We have 2 commands for reading scriptdata. But what is exactly the difference? With fgetarg you can read a certain argument, but what does freadln do exactly?

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    freadln just reads the amount of args on a line and skips to the next line after (first freadln doesnt actually skip to the next line, else you wouldnt be able to get the argcount on line 1 AND read the args)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  3. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (27th October 2015)

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    But how to use freadln properly? And is it even that usefull?

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    readfile(filename)
    {
        
    result = [];
        
    fid openfile(filename"read");
        if(
    fid == -1)
            return 
    undefined;
        
    linenum 0;
        
    argcount freadline(fid);
        while(
    argcount > -1)
        {
            
    result[linenum] = [];
            for(
    0argcounti++)
                
    result[linenum][result[linenum].size] = fgetarg(fidi);
            
    argcount freadline(fid);
        }
        
    closefile(fid);
        return 
    result;

    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (27th October 2015)

  7. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    So for example when I have a file like this
    Code:
    1234, 1245, 1236, 234645, 131233,
    How can I read all those values and store them in an array?

  8. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    readthatfile()
    {
        
    openfile("thatfile.txt""read");
        if(
    == -1)
            return;
        
    argcount freadln(f);
        if(
    argcount == -1//end of file
            
    return;
        
    result = [];
        for(
    0argcounti++)
        {
            
    result[i] = fgetarg(fi);
        }
        
    closefile(f);
        return 
    result;

    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (28th October 2015),Ni3ls (28th October 2015)

  10. #7
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Works perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •