www.webdeveloper.com
Results 1 to 4 of 4

Thread: 1- fseek number not working

  1. #1
    Join Date
    Sep 2013
    Posts
    12

    1- fseek number not working

    PHP Code:
    $file fopen("1stock.js""c+");
      
    $number fseek($file61SEEK_CUR);
      
    fwrite($file$number -1); 
    My 61st character is a number I want to do 1- that number. Why is this not working?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    fseek() does not return the character at that position, it just positions the file pointer to that position (if it succeeds) and then returns 0 on success or else -1 on failure. So after you position the pointer you then need to actually read what's at that position (e.g. fgetc(), perhaps?).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2013
    Posts
    12
    I tried this but it isn't working...
    Code:
    $file = fopen("1stock.js", "c+");
      $number = fseek($file, 61, SEEK_CUR);
      $fh = fgetc($number);
      fwrite($file, $fh -1);

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    Try something like this to see if it works:
    PHP Code:
    $file fopen("1stock.js""c+");
      
    $number fseek($file61SEEK_CUR);
      if(
    $number == -1) {
        throw new 
    Exception("fseek() failed!"); // or however else you want to handle this error
      
    }
      
    $fh fgetc($file); // fgetc() needs a file handle, not the return code from fseek()
      
    print("DEBUG: Got this value from the file: $fh"); // or error_log(), or however you like to get debug info
      
    fwrite($file$fh -1); 
    Also, I'm not sure if the fseek() position is zeroth based or not. If it is, then character 61 would be offset 60.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles