#How do I make a C program read a string from a text file?
30 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@tight cove What have you tried so far
I’m new to C, so I don’t know where to start
Google is a good place to start https://www.tutorialspoint.com/cprogramming/c_file_io.htm, https://www.programiz.com/c-programming/c-file-input-output, ...
I tried this, but I'm getting errors saying that str is the wrong variable type
Do you know what type char *str[100] is?
An array of what?
characters
Not quite
It's an array of 100 char*'s
I.e., a pointer to a character / character array
Is there a way to get fopen to read it?
You can't guess with types in C
You need to be precise
Both scanf and fopen take a string
str is not a string
How do I make a string?
A string is an array of characters
So would I do char str[100] instead of char *str[100]?
Perfect
I'm still getting an error for str's type
What is str now?
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity