Reading from file and displaying in edit box

Posted on 2004-11-05
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.
Question by:fr_cassidy
    1 Comment
    LVL 6

    Accepted Solution

    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.time, .. ) ;

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    iSeries FTP Exit Program 8 101
    has77  challenge 9 58
    Line meaning 9 60
    Path of Workbook 3 30
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
    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.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now