How can I search a file for a string and then copy it to a string variable?
How can I search a file for a string and then copy it to a string variable?
first, use fread to read into a pretty big buffer, then try something strstr() to search.
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
fgets()Originally posted by flightsimdude
How can I search a file for a string and then copy it to a string variable?
strstr()
strcpy()
strncpy()
check out http://www.rt.com/man/ for those.
Also, this might help.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
hammer thanks...I'm almost at wits end...I will look at what you have (i.e., fgets, etc) and try to incorporate it into code to search through a file to look for the string I need. I know I've said it before. I am trying to search through a file that I have opened for reading. I need to search the entire file for occurances of a particular string. I don't know if using a "while" statement with the functions you have mentioned or something similar would accomplish this?
Thanks!
Flight
What would the declaration for the charcter array look like if I want to copy the string(s) into that I find? I will need a char array that can handle up to 20 occurances of a string in a file. Each found string(s) that can be up to 40 characters in length. I wouldn't ask this question if I knew...I really don't know.
char found[20][41];Originally posted by flightsimdude
What would the declaration for the charcter array look like if I want to copy the string(s) into that I find? I will need a char array that can handle up to 20 occurances of a string in a file. Each found string(s) that can be up to 40 characters in length. I wouldn't ask this question if I knew...I really don't know.
20 occurances
40 characters + NULL
Copy can look like:
strcpy(found[3], "This string in 4th location");
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers