| | |
how to test a software program on linux
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2006
Posts: 6
Reputation:
Solved Threads: 0
There is an algorithm in the software program that other team handed to me on linux. Given a set of requirements, our task is to create a test script/driver to verify that algorithm using a separate data file and spit out the result on the output file. The concept is quite simple, but not sure if I know how to start. Please advice!!!!!
example: a C program contains an algorithm F = ma (Newton's Law). a data file for m and a is needed (each line contains data for m and a). To verify an algorithm, a test script should be written to call both data file and executable file and the output should be written either on the fly or a text file.
Thanks
example: a C program contains an algorithm F = ma (Newton's Law). a data file for m and a is needed (each line contains data for m and a). To verify an algorithm, a test script should be written to call both data file and executable file and the output should be written either on the fly or a text file.
Thanks
Salem
I do believe yer man has already said he'll be reading m and a from a file
usr1971ca, what a nice name by the way, you need to read the two numbers in from your data file; fgets() reads in a line at a time, then convert the two numbers from the digits in the input line into integers with sscanf(). Now it's just a matter of calculating their product and writing it out.
Your code might look something like this:
•
•
•
•
Ignoring the file issue for the moment, how does the program get a single 'm' and 'a' value?
•
•
•
•
using a separate data file ... a data file for m and a is needed (each line contains data for m and a).
Your code might look something like this:
C Syntax (Toggle Plain Text)
while (fgets(buf, sizeof(buf), datafile) != NULL) { if (sscanf(buf, "%d%d", &m, &a) == 2) { printf("%d * %d = %d\n", m, a, m * a); } }
Good judgment comes from experience, and a lot of that comes from bad judgment.
Oh, hang on. You don't need to write the program just a script to run it. That seems very odd because it could be as little as the name of the program followed by the name of the datafile both on one line in a text file that you make executable with chmod.
Or am I missing something here?
Or am I missing something here?
Good judgment comes from experience, and a lot of that comes from bad judgment.
•
•
Join Date: Oct 2006
Posts: 6
Reputation:
Solved Threads: 0
Salem and Risby,
Thanks for your prompt replies.
However, we will not scanf or fget within the prorgam. We probably initialize all 3 parameters for compilation purpose. The excerise here is to write another program to read a data file, which is used for a computation defined in that executable code. Its kinda hard to describe clearly here, but hope you get a picture.
Thanks
Thanks for your prompt replies.
However, we will not scanf or fget within the prorgam. We probably initialize all 3 parameters for compilation purpose. The excerise here is to write another program to read a data file, which is used for a computation defined in that executable code. Its kinda hard to describe clearly here, but hope you get a picture.
Thanks
Take your pick
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> int main ( int argc, char *argv[] ) { int m, a; if ( argc > 2 ) { m = strtol(argv[1],NULL,10); a = strtol(argv[2],NULL,10); } else { char buff[BUFSIZ]; printf( "Enter m and a values > " ); fflush( stdout ); if ( fgets( buff, sizeof buff, stdin ) != NULL ) { sscanf( buff, "%d %d", &m, &a ); } } printf( "m=%d, a=%d\n", m, a ); return 0; } # parameters on command line $ ./a.exe 22 33 m=22, a=33 # parameters entered at a prompt $ ./a.exe Enter m and a values > 33 44 m=33, a=44
•
•
Join Date: Oct 2006
Posts: 6
Reputation:
Solved Threads: 0
Salem,
Thanks very much. But that doesn't clear up my frustration.
The above source code should be pre-compiled. Data 22 33 should be one of the many data in a separate file. An objective here is to write a test script to read BOTH that data file and object code then spit out the result in a separate output file.
Your patience is appreciated
Thanks very much. But that doesn't clear up my frustration.
The above source code should be pre-compiled. Data 22 33 should be one of the many data in a separate file. An objective here is to write a test script to read BOTH that data file and object code then spit out the result in a separate output file.
Your patience is appreciated
![]() |
Other Threads in the C Forum
- Previous Thread: EXECryptor software protection
- Next Thread: Program on matrix calculations
Views: 3203 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o inches infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape socketprograming spoonfeeding stack standard strchr string strings structures student suggestions system systemcall test testautomation unix user voidmain() wab win32 win32api windows.h






