Why is this failing?


  • 0
    J

    I can't seem to figure out why this is failing... any help? Thanks

    int r4 = 0;
        int pos4 = 0;
        char[] buf4 = new char[4];
        
        public int read(char[] buf, int n) 
        {
            int i = 0;
            
            //while there are chars left from a previous read, add them
            for (;i<n && pos4 < r4;i++, pos4++)
            {
                buf[i] = buf4[pos4];
            }
            
            //if we already have what we need, return
            if (i == n)
                return i;
            
            //as long as we don't have enough
            while (i < n)
            {
                //read more
                int r4 = read4(buf4);
                pos4 = 0;
                
                //if there is nothing more to read, return what we got
                if (r4 == 0)
                    break;
                    
                //copy all characters read, up to the amount we need
                for (;i<n && pos4 < r4;i++, pos4++)
                {
                    buf[i] = buf4[pos4];
                }
            }
            return i;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.