What is the best way to read a text file and print to console, then grab that string and convert string to a const char?
VUEKID 0 Light Poster
Recommended Answers
Jump to Postif it's const char array then you won't be able to add text from a text file to it. But maybe what you want is a function whose parameter is const char*?
Jump to PostFirst, gets() gets text from the keyboard, not from a data file. What you want is fgets() to read the text file. Do you know how to read text files? If not, here is a short tutorial
Jump to Postafter line 9 add another line to call strlen() to get the length of the line just read. If you want all the lines in the file then add them up into an int variable that you can use later in the program.
[
int sum = …
All 12 Replies
DTSCode 0 Light Poster
gerard4143 371 Nearly a Posting Maven
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
VUEKID 0 Light Poster
DTSCode 0 Light Poster
gerard4143 371 Nearly a Posting Maven
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
VUEKID 0 Light Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
gerard4143 371 Nearly a Posting Maven
VUEKID 0 Light Poster

iamthwee
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.