C reading a text file line by line and printing them

I have the following C # code snippet

              string[] lines = File.ReadAllLines(@"C:\test.txt");
              for(int i=0; i<lines.Length; i++)
                  Console.WriteLine(lines[i]);

Can you help me convert it to C.

Thanks!

+4
source share
6 answers

If you plan to use Ansi Standard C, you will need fopento fgetsand printfto do what you want.

Here is a tutorial that does practically what you want .

+2
source

Take a look at fopen and fgets .

fgets , , .

+1

, :

, (ReadAllLines ) , - , , UTF16, stdout...

0

, , , , - ( / / ).

, . , , , fread/fwrite (, 4 ) .

0

++.

ifstream input("test.in");
string line;
while(getline(input, line)) {
  //Your code for the current line
}
0

fgets :

  • , , ?
  • , ?
  • , , ?

, fgets.

0
source

All Articles