LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2016, 02:02 AM   #1
hardikgohil1988
Member
 
Registered: Sep 2014
Posts: 63

Rep: Reputation: Disabled
Update Test Results to a file using c


Hello,

I am trying to write a test application which writes the test results to a file when ever test is performed.

For example the test_report.txt file contents

/********************************************************/
Diagnostic Test Report
/********************************************************/


1.RS232 Test : Not Tested
2.RS232-Front : Not Tested
3.RS232-Back1 : Not Tested
4.RS232-Back2 : Not Tested

The application should update the file as the test is performed and write Tested Ok,Test fail to this file.
 
Old 02-11-2016, 02:18 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
And? Where did you stuck? Do you have any problem at all?
 
Old 02-11-2016, 06:54 AM   #3
marius162
LQ Newbie
 
Registered: Apr 2015
Posts: 15

Rep: Reputation: Disabled
Quote:
I am trying to write a test application which writes the test results to a file when ever test is performed
Good luck. Maybe you'll go for something like

Code:
FILE *_fbla=NULL;
_fbla=fopen(<path to test_report.txt>,"a");
if(condition_indicating_successful_test){
if(_fbla!=NULL){
fprintf(_fbla,"what a success.\n");
    }//if(_fbla!=NULL){
    }//if(condition_indicating_successful_test){
else{//test failed
if(_fbla!=NULL){
fprintf(_fbla,"test #%&$ seriously.\n");
    }//if(_fbla!=NULL){
}//else{//test failed

Last edited by marius162; 02-11-2016 at 06:55 AM. Reason: Sorry for the indents, am too old to figure this out under html.
 
Old 02-11-2016, 08:40 PM   #4
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by hardikgohil1988 View Post
Hello,

I am trying to write a test application which writes the test results to a file when ever test is performed.

For example the test_report.txt file contents

/********************************************************/
Diagnostic Test Report
/********************************************************/


1.RS232 Test : Not Tested
2.RS232-Front : Not Tested
3.RS232-Back1 : Not Tested
4.RS232-Back2 : Not Tested

The application should update the file as the test is performed and write Tested Ok,Test fail to this file.
Is this a function which is part of a larger program or is it a stand-alone application?

In the latter case, a ">>" command would be just as easy as invoking a program with parameters:
echo "5.RS232-Back3 : Test fail" >> test_report.txt

Last edited by psionl0; 02-11-2016 at 11:30 PM.
 
Old 02-15-2016, 08:05 PM   #5
hardikgohil1988
Member
 
Registered: Sep 2014
Posts: 63

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by psionl0 View Post
Is this a function which is part of a larger program or is it a stand-alone application?

In the latter case, a ">>" command would be just as easy as invoking a program with parameters:
echo "5.RS232-Back3 : Test fail" >> test_report.txt

It is a stand alone application which is used to test the peripherals on-board.
 
Old 02-16-2016, 08:08 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Have you tried to follow the recommendation from marius162?

They are right, you merely need to open a file, write to it, either close it and repeat all, or leave it open and just repeat the writes to the file. There are other means to transit logs around an architecture. What have you tried as far as logs go?
 
Old 02-16-2016, 06:03 PM   #7
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by hardikgohil1988 View Post
It is a stand alone application which is used to test the peripherals on-board.
I think you might have mis-interpreted me.

No matter, if you want to add lines to an external file, just use the system() function. (You could also use fopen(), fprintf() if you want to do more work).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
smartctl hdd test results interpretation please! Completely Clueless Linux - Hardware 4 04-14-2014 08:19 AM
[SOLVED] test, [ and [[ not delivering the same results :( grail Programming 2 11-23-2010 10:27 PM
yum update dbus results in file conflict dvlierop Fedora 2 11-13-2005 03:21 AM
Glibc Pass II Test Results g_goblin Linux From Scratch 0 11-17-2003 12:42 PM
Leak Test results Zvezda Linux - Security 12 03-13-2002 05:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration