472,950 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

opening a file, searching a string, getting data

Hello all,

I'm a chemical engineering student. our teacher has given us a project to do some calculations based on some equations. those equations include constants, which are to be read from a file(I don't understand why?) i took an introductory course on c programming but the curriculum didn't include opening files, searching files and getting data from files. i made some searching through google and learned about opening and closing files, but i still don't know how to search for a string and how to get data from the same line as the string.

any help here would be appreciated. Thanks.
Jan 15 '08 #1
6 3278
sicarie
4,677 Expert Mod 4TB
I personally like this tutorial - it'll refresh you on the basics, as well as provide a reference for whatever File IO stuff you may need.

If you have any trouble coding it, feel free to post, though we do request that you take a gander at the Posting Guidelines.

Good luck!
Jan 15 '08 #2
I personally like this tutorial - it'll refresh you on the basics, as well as provide a reference for whatever File IO stuff you may need.

If you have any trouble coding it, feel free to post, though we do request that you take a gander at the Posting Guidelines.

Good luck!

I did look at the guidelines, and the program I'll write actually is a lot longer than the searching function. : )

thanks for the tutorial, but I don't know c++, I was inquiring about c. are there any sources for c tutorials like this one?
Jan 15 '08 #3
sicarie
4,677 Expert Mod 4TB
Ah, right, sorry about that - missed that part. Does this look like it will help?
Jan 15 '08 #4
Ah, right, sorry about that - missed that part. Does this look like it will help?
I looked at that one before, and there are actually questions in my mind about this one.

When I'm reading from a file, where do i put the file and what do i write for the filename part when using fopen(filename, mode)? for example, if my file is constants.txt, where should it be located for the program to see it and what should i write for the filename part?

in addition, this does not provide information about the behaviour of the functions fscanf and fprintf. for instance, in the while loop, it says to go on until end of file is reached. however, how does it pass to the next line in the file? does fscanf do it automatically?

i thought of that source to be inadequate. sorry to be bothering you so much but i looked at first 2 or 3 pages of google search when i type "c file open", "c fopen", "c search file" and "c file access" (searching each separately). any other help would be wonderful. : )

thanks, by the way : )
Jan 15 '08 #5
gpraghuram
1,275 Expert 1GB
I looked at that one before, and there are actually questions in my mind about this one.

When I'm reading from a file, where do i put the file and what do i write for the filename part when using fopen(filename, mode)? for example, if my file is constants.txt, where should it be located for the program to see it and what should i write for the filename part?

in addition, this does not provide information about the behaviour of the functions fscanf and fprintf. for instance, in the while loop, it says to go on until end of file is reached. however, how does it pass to the next line in the file? does fscanf do it automatically?

i thought of that source to be inadequate. sorry to be bothering you so much but i looked at first 2 or 3 pages of google search when i type "c file open", "c fopen", "c search file" and "c file access" (searching each separately). any other help would be wonderful. : )

thanks, by the way : )

fopen takes two parameters
first is the file name(which u can specify the full path) and second is the mode
that is write or read etc.
When reading u can use fgets and every time you use fgets it automatically goes to the next line which is hanled by the System

Raghuram
Jan 15 '08 #6
sicarie
4,677 Expert Mod 4TB
There's also our tutorial on C File IO.
Jan 16 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roberto Dias | last post by:
Hi, I've got a text file and I need to capture some data in it. I implemented ( using comp.lang.c++ help) a typical searching algorithm that first find the header (label that identifies the data...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
0
by: Marco Castro | last post by:
Im trying to create a system service that will read some records within an access file. From these values I will then be able to see if other software in the system is up to date and install the...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
3
by: 2005 | last post by:
Hi I have a file that I am opening with void main() { ifstream inFile("assign.data"); if (!inFile) {
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
1
by: warheart | last post by:
hi im kinda new to programming i aint lazy to search and learn :D but i am getting despirate... ive been looking everywhere for a code to search a txt file and find a string, and then give...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.