Jump to content

File handling

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
001

001

    Newbie

  • Members
  • Pip
  • 4 posts
Hi readers i am new to C# programming and new to this forum. i need help with the C# file handling.
the problem is the "Console.WriteLine("Enter a name to be put in the file");" i don't want to write the name in, i want the program to automatically input the data inside to that it can save it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Filehandling
{
class Program
{
static void Main(string[] args)
{

StreamWriter writer = new StreamWriter(@"F:\TESTAA2.txt");
Char Reply;

Console.WriteLine("Here is an example of writing data to a”
+ “file\n\n");

do
{
Console.WriteLine("Enter a name to be put in the file");
string Fname = Console.ReadLine();
writer.WriteLine(Fname);
Console.WriteLine("more?");
Reply = Char.Parse(Console.ReadLine());
} while (Reply != 'N');
Console.ReadLine();
writer.Close();


//-------------------------------------
/*Pass the file you want to read into the streamreaders
reader object*/
StreamReader reader = new StreamReader(@"F:\TESTAA2.txt");


Console.WriteLine("The names in the file are:");


while (!reader.EndOfStream)// while not at the end of the file
{
string linefromAA2 = reader.ReadLine();
Console.WriteLine(" " + linefromAA2);
}
reader.Close();
Console.ReadLine();
}
}
}

#2
001

001

    Newbie

  • Members
  • Pip
  • 4 posts
the program is for a restaurant program. the program allows users to input what they want (pizza, drink and extras) than the program would calculate it and give out the result (total cost).
i want the file handling program to save the whole program otherwise the total price. please guys if you have any ideas please tell me!

#3
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
1. I don't see anything wrong, what is your error?
2. Edit your post and place the code between [code ] tags [/ code] so that I can read it easier.
3. I suggest reading this tutorial to understand the basics of C#: http://www.scribd.co...ogramming-Basic
It might help you a lot.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#4
001

001

    Newbie

  • Members
  • Pip
  • 4 posts
Davide i know that no errors are found in this program but i want the program to save sections of the program. for example the calculation result when the orders have been made.
on this program it lets me input names >>> Console.WriteLine("Enter a name to be put in the file"); but i dont want this to happen.