473,408 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 3304
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.