-
# include <stdio.h>
-
# include <stdlib.h>
-
# include <math.h>
-
# define M_SQRT
-
/* macro to insert blank lines on screen */
-
#define BLANK_LINE(n) {int i=0;for(i<(n);i++)fprintf(stderr,"\n";}
-
-
void print_message(void);
-
void fpos(FILE*outfile,float a,float b,float c,float d);
-
void fzero(FILE*outfile,float a,float b,float c,float d);
-
void fneg(FLIE*outfile,float a,float b,float c,float d);
-
-
int main(void){
-
int comp;
-
float a, b, c, d, x1,x2;
-
FILE *infile, *outfile;
-
-
infile=fopen("abc.txt","r");
-
outfile=fopen("roots207.txt,"w");
-
print_message();
-
-
while(EOF !=fscanf(infile,"%f%f%f",&a,&b,&c)){
-
-
d = b*b-4*a*c;
-
-
ax^2 + bx +c = 0 ;
-
-
x1 = (-b + sqrt(b*b - 4ac)) / 2a);
-
x2 = (-b - sqrt(b*2 - 4ac)) / 2a);
-
-
if(a==0 && b==0 && c==0)
-
code = 1;
-
else if(a==O && b!=0 && c==0)
-
code = 2;
-
else if(a==0 && b!=0 && c!=0)
-
code = 3;
-
else if(a>0 && d==0)
-
code = 4;
-
else if(a<0 && d==0)
-
code = 5;
-
else if(a!=0 && d<0)
-
code = 6;
-
switch(code) {
-
code 1:
-
root1(outfile,a,b,c);
-
break;
-
code 2:
-
root2(outfile,a,b,c);
-
break;
-
code 3:
-
root3(outfile,a,b,c);
-
break;
-
code 4:
-
root4(outfile,a,b,c);
-
break;
-
code 5:
-
root5(outfile,a,b,c);
-
break;
-
code 6:
-
root6(outfile,a,b,c);
-
break;
-
default:
-
puts("ERROR1: Never get here!");
-
}/* end switch-case */
-
}/* end while() */
-
fclose(infile);
-
fclose(outfile);
-
return;
-
/*----------------function definitions---------------------- */
-
void print_message(void){
-
BLANK_LINES(16)
-
/* the following sends output to screen even when output redirected */
-
fprintf(stderr,
-
"--------------------------------------------------------\n"
-
"INPUT: from file abc.txt\n"
-
"OUTPUT: to file roots207.txt\n"
-
"Each row must contain three real numbers.\n"
-
"Program terminates when end-of-file is reached$
-
"---------------------------------------------------\n"
-
);
-
BLANK_LINES(16);
-
return;
-
}
-
void root1(FILE* outfile,double a,double b,double c,double d,double x1,double x2){
-
fputs("--------------------------------------------\n", outfile);
-
fprintf(outfile,"(a,b,c) = (%4.1f,%4.1f,%4.1f), %fx^2+%fx+%f=0=%8.4f, \n",a
-
fprintf(outfile,"has an an infinity of roots: all complex numbers are roots$
-
i just start doing C so this is as far as i can go can any1 so me what to do next so my program can work
thx
1 1353
There are some syntax errors and some calls to non-existent functions.
You should check that all constant strings you would like to print with fprintf are enclosed in quotes:
fprintf(stderr,"This is an error );
fprintf(stderr,"This is correct");
and you should also check that all brackets are matched: whenever you open a bracket there must be the correponding closing one:
fprintf(stderr,"\n"; // this is an error
fprintf(stderr,"\n"); //this is correct
The for statement takes three parameters: for(initial condition; expression1; expression2), so that the correct syntax will be:
for(int i=0;i<n;i++) fprintf(stderr,"\n");
You can also omit some parameters, by leaving blank their position
int i=0; for( ;i<n;i++) fprintf(stderr,"\n");
In the switch statement, you should not repeat for each case the variable which you are checking the value for. Instead you should write a "case" keyword followed by the value tha variable is checked against:
switch(code)
{
case 1: //code for the case code=1
break;
case 2: //code for the case code=2
break;
default: //code for the default case
}
Finally, you are using the function root1 before having defined it. You should place its prototype together with those of the other functions(fpos, fzero, fneg and print_message), so that the "main" knows of its existence. The same goes with the other functions root2, ... ,root6, that have never been defined.
Hope this will help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: fabrice |
last post by:
Hello,
I've got trouble reading a text file (event viewer dump) by using the
getline() function...
After 200 - 300 lines that are read correctly, it suddenly stops
reading the rest of the...
|
by: George Copeland |
last post by:
This is a request for help fixing a SQL Server 2000/ADO problem on Windows
XP. I would appreciate any useful assistance.
PROBLEM: SQL Server access on my machine fails as follows:
1. All of...
|
by: fripper |
last post by:
I posted this problem a couple of days ago but felt I might have better luck
re-stating the problem.
Apparently I messed up IIS (v. 5) somehow because I am suddenly unable to
load web forms! A...
|
by: Ian Stanley |
last post by:
Hi,
Continuing my strcat segmentation fault posting-
I have a problem which occurs when appending two sting literals using
strcat.
I have tried to fix it by writing my own function that does the...
|
by: Sarah |
last post by:
I need to access some data on a server. I can access it directly using UNC
(i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network
drive resource (S:\Path\FileName).
Here is my...
|
by: Prasad |
last post by:
HI,
I am a beginner in VC++..
I am trying to write a Win32 console application in visual studio..
I am using following header files..
#include <STRING>
using namespace std;
#include...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
|
by: Ron |
last post by:
Hi All,
I've recently installed a program written in Access 2000 on a laptop. The
laptop had an existing Office 2000 Pro which of course included Access. But
the program acts oddly (more oddly...
|
by: pereges |
last post by:
I have a C program which I created on Windows machine. I have compiled
and executed the program on windows machine and it gives me the
consistent output every time i run it. for eg.
input a = 2,...
|
by: fido19 |
last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp).
Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha
was tall and handsome –...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |