How to Read a File Line at a Time in C

The Visual C software development language lets you read any external file one line at a time. You use this Visual C method to read variables located in a system or program file. The information is stored in a string variable, and you can either store the information in a database or display the information on the Windows form.

Instructions

    • 1

      Open the Visual Studio software and the C project you want to edit. Double-click the code file to load the file in the editor.

    • 2

      Define the file you want to import. You import the file into a "StreamReader" variable, which contains the file's information, so you can read it line by line. Add the following code to your functions:

      System.IO.StreamReader file = new System.IO.StreamReader("c:\myfile.txt");

      Replace "myfile.txt" with your own file name.

    • 3

      Read one line from the file. The following code reads the first line from the file:

      data = file.ReadLine();

    • 4

      Display the information to the reader. The following code shows the information from the file to the reader:

      Console.WriteLine(data);

Related Searches

References

Related Ads

Check It Out

Geek Vs Geek: We Fly Drones, Accidents Ensue