?
Solved

Reading from file and displaying in edit box

Posted on 2004-11-05
1
Medium Priority
?
173 Views
Last Modified: 2013-11-20
Hello Experts,
Ok here's what I am trying to do:
I have a text file which has a row of readings for date, time, tempeature, rain, windspeed.
What I am doing is designing a GUI where a user can click a button and get latest temperature to appear in an edit box.(the latest reading is always in the same file).

For testing purposes i have a file just containg a number representing temperature and when I click the button the ascii value for the number in the file appears. Is there a function that will covert ascii to char or int?

Also my C++ programming skills are nothing special, I am just using fgetc to read from the file. If I want to have another button to say get curent rainfall or windspeed. How do I actualy navigate my way around the file. assuming its structured like:
date        time         tempeature          rain             windspeed
What is the difference in fgets and fgetc? is it simply to read a string (1 whole line ) and character( 1 digit)?

Would it be easier if i skipped a line between each reading instead of using tabs? Its in this format because its being dumped into a database and it is supposed to be in this form. i was hoping I could use the one file for dumping to database and viewing the latest rading from the GUI.  

Thanks for any help.
fr
0
Comment
Question by:fr_cassidy
1 Comment
 
LVL 6

Accepted Solution

by:
Amritpal Singh earned 150 total points
ID: 12511680
for reading file use a structure

struct myrecord
{
     char date[SIZE]
     char time[SIZE]
     .....
};
struct myrecord r;
FILE *fp;
fp = fopen("filename","r");
while ( fread ( &r, sizeof ( r ), 1, fp ) == 1 )
    printf ( "\n%s %s %s", r.date, r.time, .. ) ;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question