Users Online

· Guests Online: 6

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Read Data from Stream and Convert Data to Chars

C# Program to Read Data from Stream and Convert Data to Chars

 

 

This is a C# Program to read data from stream and cast data to chars.

Problem Description

This C# Program Reads Data from Stream and Cast Data to Chars.

Problem Solution

Here the string from the file is converted into character data.

Program/Source Code

Here is source code of the C# Program to Read Data from Stream and Cast Data to Chars. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Read Data from Stream and Cast Data to Chars
 */
using System;
using System.IO;
public sealed class Program
{
    public static void Main()
    {
        using (Stream s = new FileStream(@"c:\sri\srip.txt", FileMode.Open))
        {
            int read;
            while ((read = s.ReadByte()) != -1)
            {
                Console.Write("{0} ", (char)read);
            }
            Console.ReadLine();
        }
    }
}
Program Explanation

This C# program is used to read data from stream and cast data to chars. The ReadByte() function is used to read a byte from the file and advances read the position one byte. Using while loop checks the line is not equal to -1. If the condition is true then execute the iteration of the loop. The string from the file is converted into character data.

 
Runtime Test Cases
 
G O O D M O R N I N G

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.28 seconds
15,067,415 unique visits