473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

i have problem with these program

Expand|Select|Wrap|Line Numbers
  1. # include <stdio.h>
  2. # include <stdlib.h>
  3. # include <math.h>
  4. # define M_SQRT
  5. /* macro to insert blank lines on screen */
  6. #define BLANK_LINE(n) {int i=0;for(i<(n);i++)fprintf(stderr,"\n";}
  7.  
  8. void print_message(void);
  9. void fpos(FILE*outfile,float a,float b,float c,float d);
  10. void fzero(FILE*outfile,float a,float b,float c,float d);
  11. void fneg(FLIE*outfile,float a,float b,float c,float d);
  12.  
  13. int main(void){
  14.     int comp;
  15.     float a, b, c, d, x1,x2;
  16.     FILE *infile, *outfile;
  17.  
  18.     infile=fopen("abc.txt","r");
  19.     outfile=fopen("roots207.txt,"w"); 
  20.  print_message();
  21.  
  22.     while(EOF !=fscanf(infile,"%f%f%f",&a,&b,&c)){
  23.  
  24.     d = b*b-4*a*c;
  25.  
  26.     ax^2 + bx +c = 0 ;
  27.  
  28.     x1 = (-b + sqrt(b*b - 4ac)) / 2a);
  29.     x2 = (-b - sqrt(b*2 - 4ac)) / 2a);
  30.  
  31.     if(a==0 && b==0 && c==0)
  32.         code = 1;
  33.     else if(a==O && b!=0 && c==0)
  34.         code = 2; 
  35.     else if(a==0 && b!=0 && c!=0)
  36.         code = 3;
  37.     else if(a>0 && d==0)
  38.         code = 4;
  39.  else if(a<0 && d==0)
  40.         code = 5;
  41.     else if(a!=0 && d<0)
  42.         code = 6;
  43.   switch(code) {
  44.     code 1:
  45.         root1(outfile,a,b,c);
  46.         break;   
  47.     code 2:
  48.         root2(outfile,a,b,c);
  49.   break;
  50.     code 3:
  51.         root3(outfile,a,b,c);
  52.         break;   
  53.    code 4:
  54.         root4(outfile,a,b,c);
  55.         break;
  56.     code 5:
  57.         root5(outfile,a,b,c);
  58.         break;
  59. code 6:
  60.         root6(outfile,a,b,c);
  61.         break;
  62.     default:
  63.         puts("ERROR1: Never get here!");
  64.     }/* end switch-case */
  65. }/* end while() */
  66.     fclose(infile);
  67.     fclose(outfile);
  68.     return;
  69. /*----------------function definitions---------------------- */
  70. void print_message(void){
  71.   BLANK_LINES(16)
  72. /* the following sends output to screen even when output redirected */
  73. fprintf(stderr,
  74.     "--------------------------------------------------------\n"
  75.                                 "INPUT: from file abc.txt\n"
  76.                                 "OUTPUT: to file roots207.txt\n"
  77.                                 "Each row must contain three real numbers.\n"
  78.                                 "Program terminates when end-of-file is reached$
  79.    "---------------------------------------------------\n"
  80. );
  81.   BLANK_LINES(16);
  82. return;
  83. }
  84. void root1(FILE* outfile,double a,double b,double c,double d,double x1,double x2){
  85.     fputs("--------------------------------------------\n", outfile);
  86.     fprintf(outfile,"(a,b,c) = (%4.1f,%4.1f,%4.1f), %fx^2+%fx+%f=0=%8.4f, \n",a
  87.     fprintf(outfile,"has an an infinity of roots: all complex numbers are roots$
  88.  
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
Feb 16 '07 #1
1 1353
enri
10
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.
Feb 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
5
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...
5
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...
18
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...
8
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...
9
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...
5
blazedaces
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...
9
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...
87
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,...
6
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 –...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.