Link to home
Start Free TrialLog in
Avatar of fattumsdad
fattumsdad

asked on

Console - Read Text File

Let's say I have a text file called "Test.txt".  In this text file, there are numerous lines containing punctuation, numbers, etc.  How do I read that file and display it in the console?  
SOLUTION
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fattumsdad
fattumsdad

ASKER

jkr,

Do I have to link to a lib?  I get:

C:\MinGWStudio\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.1\..\..\..\libmingw32.a(main.o)(.text+0x97):main.c: undefined reference to `WinMain@16'

As for the special formatting, is there a way to read it in exactly as it appears in the text file?
>>Do I have to link to a lib?

No, just set up your project to link a console app, not a GUI app :o)

>>As for the special formatting, is there a way to read it in exactly as it appears in the text file?

That's wht the above code fragment does. The only difference will be the line wrap when a line exceeeds the console width.
This is really strange....  I have it set up as Win32 Console Application...  the same setting that I've been using the other million times you've helped me LOL.  Still getting the same error... :\
Check again - it might just be something simple :o)
I have it in exactly as you showed...  should I add:

int main()
{
  CoutTextFile("c:/Test.txt");
  return 0;
}
OMG

Yes.
Sorry - I have been following this question and I am disgusted in myself that I did not spot that that was the problem.  I did not mean any offence to you :)

Back to the books for me :)
>> CoutTextFile("c:/Test.txt");

Probably better to be CoutTextFile("c:\\Test.txt");
Got it.  It seems to work the same both ways, "c:/" or "c:\\"...  is there a significant difference?
>>It seems to work the same both ways, "c:/" or "c:\\"...  is there a significant difference?

No, not at all. Both are valid on Win32 platforms.
Not really.  Sometimes a backslash is preferred, but if you do you must use two (\\) as \ is an escape character.

Ta for the assist.
Ok...  one more question...  actually, I'll repost to give more points :)  Thank for the help guys!
Glad to help.