what does abc.dat contain?

if it is abcdefghijklmnopqrstuvwxyz

then your output will be:

                   zyxwvutsrqponmlkjihg

this is because your seek origin is at the end, and as usman
explained, reading forward from this point will bring back char
65535.  Once you hit i = 0 it will return the end character, then -1
will read the second to last, -2 the third to last etc.


if you want to read from t backwards, the following loop should do it:

            for(int i=20; i>=0; i--)
            {
                f.Seek(i, SeekOrigin.Beginning); // this may be start
- check the enum
                ch= (char)f.ReadByte();
                Console.Write(ch+" ");
            }


VIKAS GARG    View profileusing System; using System.IO; class Program
{     static void Main(string[] args)     {         FileStream
f;         char ch;         try         {             f = new
FileStream("abc.dat", FileMode.Create);         }         catch
(IOException exc)
{             Console.WriteLine(exc.Message);
return;         }         for (int i = 0; i < 26; i++)
{             try             {                 f.WriteByte((byte)('A'
+ i));             }             catch (IOException exc)
{                 Console.WriteLine(exc.Message);
return;             }         }         try
{             Console.WriteLine();             Console.WriteLine("Here
is every other value");             for(int i=20; i>-20; i-
=1)             {                 f.Seek(i,
SeekOrigin.End);                 ch=
(char)f.ReadByte();                 Console.Write(ch+"
");             }         }         catch(IOException exc)
{             Console.WriteLine(exc.Message);
return;         }         f.Close();     } } How is this block working
in the above program Here the concept of SeekOrigin.End is bit
confusing             for(int i=20; i>-20; i-=1)
{                 f.Seek(i, SeekOrigin.End);                 ch=
(char)f.ReadByte();                 Console.Write(ch+"
");             }
  More options 5 Nov, 11:30

From: "VIKAS GARG" <[EMAIL PROTECTED]>
Date: Wed, 5 Nov 2008 17:00:23 +0530
Local: Wed 5 Nov 2008 11:30
Subject: Seek End
Reply | Reply to author | Forward | Print | Individual message | Show
original | Report this message | Find messages by this author
using System;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        FileStream f;
        char ch;
        try
        {
            f = new FileStream("abc.dat", FileMode.Create);
        }
        catch (IOException exc)
        {
            Console.WriteLine(exc.Message);
            return;
        }
        for (int i = 0; i < 26; i++)
        {
            try
            {
                f.WriteByte((byte)('A' + i));
            }
            catch (IOException exc)
            {
                Console.WriteLine(exc.Message);
                return;
            }
        }
        try
        {


            Console.WriteLine();
            Console.WriteLine("Here is every other value");
            for(int i=20; i>-20; i-=1)
            {
                f.Seek(i, SeekOrigin.End);
                ch= (char)f.ReadByte();
                Console.Write(ch+" ");
            }
        }
        catch(IOException exc)
        {
            Console.WriteLine(exc.Message);
            return;
        }
        f.Close();
    }



}


How is this block working in the above program
Here the concept of SeekOrigin.End is bit confusing





On 6 Nov, 06:32, "VIKAS GARG" <[EMAIL PROTECTED]> wrote:
> In my proggThere are two for loops
> Using the first for loop, I had took or copies the output in a file
> "abc.dat"
> then using second for loop I had took the output on the console.
>
> Concentrate on my second for loop
> that is
>              for(int i=20; i>-20; i-=1)
> And I am trying to seek from the last value. Not when i is 20, the origin is
> 20th alphabet, that is "T" means my progg should consider "T" as the last
> alphabet. and moves backward by one position. Next output should be "S".
> This is all what I think.
> I know output is not coming according to my expectation. This means I am
> wrong somewhere in my concepts
> Please Usman tell me where am I wrong

Reply via email to