ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I’m working on an embedded Linux platform and I’ve created an application in C++. The application creates and opens 3 data files using;
1 files declared global
ofstream datafileA;
ofstream datafileB;
ofstream datafileC;
2 files opened in main()
datafileA.open("rawdataA.dat");
datafileB.open("rawdataB.dat");
datafileC.open("rawdataC.dat");
3 write data to the files in add_data()
datafileA <<dataA<<" , "<<"count= "<< count<<endl;
datafileB << dataB<<" , "<<"count= "<< count<<endl;
datafileC << dataC <<" , "<<"count= "<< count<<endl;
4. close files
datafileA.close()
datafileB.close()
datafileC.close()
The application is very simple, it just runs in forever loop writing data to file until the user hits cntrl + c to end the application. Consistantly datafileB and datafileC hold quite a few points, something that looks realistic to the amount of time that the application has been running. DatafileA on the other hand, seems to quit loging after only a small number of datapoints?
Three files all handled identically, data retrieved and written to identically. I can’t seem to figure out why datafileA is consistently not working. Any help is greatly appreciated.
You should show smallest excerpt from your code which is not working, because with this code isn't anything wrong. Stopping an application with CTRL+C is not a good method, if you does not handle this signal (it is SIGINT) in your application and gracefully close all file handles, etc. Can you confirm that data saved in this file is different than for example displayed simultaneously on the screen?
It's funny you ask about printing to the screen as well to verify if the data is still available. I actually did that experiment to test it, in fact the three data points do continue printing to the screen. The B and C files continue to get updated while the A file stops after short value.
I agree that I'm not handling the closing of the application and files very gracefully yet, that could be my problem? I would expect the same problems with all files, not just one.
I'll put together an excerpt and post it, but what I posted was basically a cut and paste of file handling throughout the code.
I'm going to work on the signal( SIGINT) now to see if that works.
Have you tried rearranging the order of the writes?
Try another data file, i.e. a fourth see what happens.
Try using C stdio instead.
Are they open for append?
Try open, append, close, open, append, close etc...
So if data on screen and on file are the same then there is no problem with writing file. The bug most probably is elsewhere. Can you show how this data is readed and written?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.