Coder Social home page Coder Social logo

sanjay5656 / 19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aswini-j/19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation

0.0 0.0 0.0 4 KB

C# 100.00%

19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation's Introduction

19AI308-Object-Oriented-Programming-using-CSharp-Exp-10-File-Manipulation

Develop a C# program to get the values from the user using structure and store it in a file in a specific path using file stream concept

AIM:

To develop a C# program using file streams.

ALGORITHM:

Step 1:

Define a structure UserData to hold user data fields like name, age, and email.

Step 2:

Create an array of UserData to store multiple user data entries. Use a loop to prompt the user to input their name, age, and email, and store the input in the array.

Step 3:

Specify the file path where the user data will be stored.

Step 4:

Inside the loop, for each user data entry, open the file in append mode using StreamWriter and write the user data to the file.

Step 5:

Close the file after writing all user data.

Step 6:

Display a message indicating that the user data has been saved to the file.

PROGRAM:

Developed by    : Sanjay S
Register number : 212221243002

using System;
using System.IO;
struct UserData
{
    public string Name;
    public int Age;
    public string Email;
}
class Program
{
    static void Main(string[] args)
    {
        string filePath = @"C:\Users\SEC\Desktop\exp10.txt";
        UserData[] ud=new UserData[3];
        for(int i=0; i<3;i++)
        {
            Console.WriteLine("Enter your name:");
            ud[i].Name = Console.ReadLine();

            Console.WriteLine("Enter your age:");
            ud[i].Age = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter your email:");
            ud[i].Email = Console.ReadLine();

            WriteUserDataToFile(filePath, ud[i]);
        }  
        Console.WriteLine("User data has been saved to the file.");
    }

    static void WriteUserDataToFile(string filePath, UserData userData)
    {
        //using (FileStream fs = new FileStream(filePath, FileMode.Create))
        using (StreamWriter writer = File.AppendText(filePath))
        {
            writer.WriteLine($"Name: {userData.Name}");
            writer.WriteLine($"Age: {userData.Age}");
            writer.WriteLine($"Email: {userData.Email}");
        }
    }
}

OUTPUT:

Screenshot (92)

RESULT:

Thus the C# program to get the values from the user using structure and store it in a file in a specific path using file stream concept executed successfully.

19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation's People

Contributors

sanjay5656 avatar aswini-j avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.