Help. Where is my error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Red Dragon

    #16
    Re: Help. Where is my error?

    > Well, whatever you've done worked for this post, at least - we'll let[color=blue]
    > you know if the problem occurs again.[/color]

    This post of course works because I dont have any C- program loaded on it.
    I have yet to see when I paste a C-program on it, what will be its
    outcome.

    Now I paste from Notepad and not directly from Visual C++ platform.
    Please let me know if the problem occurs again.
    Thanks
    Khoon.





    Comment

    • Tim Rentsch

      #17
      Re: Help. Where is my error?

      "Red Dragon" <tskhoon@stream yx.com> writes:
      [color=blue][color=green]
      > >
      > > You have been repeatedly asked not to post using HTML.
      > > Please stop it. This is usenet, not some mailing list or forum.[/color][/color]
      [snip][color=blue]
      >
      > Mr. Michael,
      > I wish to apologize for causing you problem. I did not know I was causing a
      > problem.
      > 1. The dont understand the HTML thing. I did not use HTML. What I did was
      > to copy from my Visual C++ platform and paste on the Outlook Express
      > screen. With Mr. Skarmander's instruction, I have set the radio button to
      > "Plain Text" on the Send Tab and thought the problem is solved. I have
      > actually sent a copy of the outgoing mail to myself and I dont see any HTML
      > thing on my screen on the returned copy. So I dont know what else to do.[/color]

      I suggest trying a mail tool other than Microsoft Outlook Express.
      Microsoft mail software is well known for behaving in ways that
      can cause problems like this.

      Probably what you're using to read news hides the HTML-ness
      of what you're posting. FYI, here is what gets transmitted
      (each line has '>->-> ' at the beginning). I expect you can
      see why other people don't like reading postings like this.

      [color=blue]
      >->-> From: "Red Dragon" <tskhoon@stream yx.com>
      >->-> Subject: Re: Help. Where is my error?
      >->-> Newsgroups: comp.lang.c
      >->-> Date: Tue, 18 Oct 2005 20:43:20 +0800
      >->-> Organization: TMnet Malaysia[/color]
      References: <4353ae06_1@new s.tm.net.my> <1129584706.068 328.31530@g43g2 000cwa.googlegr oups.com> <4354e645$1_2@n ews.tm.net.my>
      Lines: 281
      MIME-Version: 1.0
      Content-Type: multipart/alternative;
      boundary="----=_NextPart_000_ 000E_01C5D424.9 4159240"
      X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
      X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
      NNTP-Posting-Host: 218.111.62.120
      X-Original-NNTP-Posting-Host: 218.111.62.120
      Message-ID: <4354edf1_2@new s.tm.net.my>
      X-Trace: news.tm.net.my 1129639409 218.111.62.120 (18 Oct 2005 20:43:29 +0800)
      Path: nntp-server.caltech. edu!hammer.uore gon.edu!news.gl orb.com!news-feed01.roc.ny.f rontiernet.net! nntp.frontierne t.net!uunet!spo ol.news.uu.net! ash.uu.net!news 1.tm.net.my!not-for-mail[color=blue]
      >->->
      >->-> This is a multi-part message in MIME format.
      >->->
      >->-> ------=_NextPart_000_ 000E_01C5D424.9 4159240
      >->-> Content-Type: text/plain;
      >->-> charset="iso-8859-1"
      >->-> Content-Transfer-Encoding: quoted-printable
      >->->
      >->-> I have got all the results by using 2 scanf(). One is a dummy. I am =
      >->-> also using double instead of float.=20
      >->-> Below are the results. I am copying and paste from Notepad, so I hope =
      >->-> I dont have HTML problem.=20
      >->-> Regards,
      >->-> Khoon
      >->->
      >->->
      >->-> /* Roots of a Quadratic Equation.
      >->-> 12.10.05 */
      >->->
      >->-> #include <stdio.h>
      >->-> #include <stdlib.h>
      >->-> #include <math.h>
      >->->
      >->-> int main (void)
      >->->
      >->-> {
      >->-> int a; int b; int c; double x1; double x2; double E; int E1; double R; =
      >->-> double I;double S;
      >->-> char q; char Y;
      >->->
      >->-> printf ("Please key in the value of constant a,b and c for finding the =
      >->-> roots of quadratic");
      >->-> printf ("equation ax%c+bx+c=3D0 :",253);
      >->-> scanf ("%d%d%d", &a,&b,&c);
      >->-> =20
      >->-> E =3D(b*b)-(4*a*c);
      >->-> =20
      >->-> if ( E > 0)=20
      >->-> { =20
      >->-> x1 =3D (float)(-b+sqrt(E))/(2*a);
      >->-> x2 =3D (float)(-b-sqrt(E))/(2*a);
      >->->
      >->-> printf ("\nYour quadratic equation has two distinct real roots: =
      >->-> x1=3D%1.6f ,x2=3D%1.6f",x1 ,x2);
      >->-> }
      >->-> =20
      >->-> else if (E =3D=3D 0)=20
      >->-> {
      >->->
      >->-> x1 =3D (float)(-b+sqrt(E))/(2*a);
      >->-> =20
      >->-> printf ("\nYour quadratic equation has two same: =
      >->-> x1=3Dx2=3D%1.6f \n",x1);
      >->-> }
      >->-> =20
      >->-> else=20
      >->->
      >->-> {
      >->->
      >->-> printf ("Your quadratic equation has two distinct imaginary roots. Do =
      >->-> you want to know");
      >->-> printf ("\nthe values of the imaginary roots (Y/N)?");
      >->-> =20
      >->-> scanf ("%c",&q); /* Dummy. The computer jumps this =
      >->-> scanf() */
      >->->
      >->-> scanf ("%c",&q);
      >->->
      >->-> printf ("q =3D %c\n",q); /* Test statement*/
      >->->
      >->-> if ('Y'=3D=3Dq)
      >->-> {
      >->-> R =3D (float)-b/(2*a);
      >->-> S=3Dabs(E);
      >->-> S=3Dsqrt(S);
      >->-> I =3D S/(2*a);
      >->-> printf ("\nThe imaginary roots are:\n");
      >->-> printf (" x1=3D%1.6f + %1.6fi , x2=3D%1.6f - %1.6fi\n",R,I,R ,I);
      >->-> }
      >->-> else
      >->-> printf ("Thank you for using this computer\n");
      >->-> }
      >->-> return 0;
      >->-> }
      >->->
      >->-> /* RESULT
      >->-> Please key in the value of constant a,b and c for finding the roots of =
      >->-> quadratic
      >->-> equation ax=B2+bx+c=3D0 :3 4 1
      >->->
      >->-> Your quadratic equation has two distinct real roots: x1=3D-0.333333 =
      >->-> ,x2=3D-1.000000
      >->-> Press any key to continue */
      >->->
      >->-> /*Please key in the value of constant a,b and c for finding the roots of =
      >->-> quadratic
      >->-> equation ax=B2+bx+c=3D0 :1 8 16
      >->->
      >->-> Your quadratic equation has two same: x1=3Dx2=3D-4.000000
      >->-> Press any key to continue */
      >->->
      >->-> /*Please key in the value of constant a,b and c for finding the roots of =
      >->-> quadrati
      >->-> equation ax=B2+bx+c=3D0 :4 2 5
      >->-> Your quadratic equation has two distinct imaginary roots. Do you want =
      >->-> to know
      >->-> the values of the imaginary roots (Y/N)?Y
      >->-> q =3D Y
      >->->
      >->-> The imaginary roots are:
      >->-> x1=3D-0.250000 + 1.089725i , x2=3D-0.250000 - 1.089725i
      >->-> Press any key to continue*/
      >->->
      >->-> /*Please key in the value of constant a,b and c for finding the roots of =
      >->-> quadratic
      >->-> equation ax=B2+bx+c=3D0 :4 2 5
      >->-> Your quadratic equation has two distinct imaginary roots. Do you want =
      >->-> to know
      >->-> the values of the imaginary roots (Y/N)?N
      >->-> q =3D N
      >->-> Thank you for using this computer
      >->-> Press any key to continue*/
      >->-> =20
      >->->
      >->-> ------=_NextPart_000_ 000E_01C5D424.9 4159240
      >->-> Content-Type: text/html;
      >->-> charset="iso-8859-1"
      >->-> Content-Transfer-Encoding: quoted-printable
      >->->
      >->-> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      >->-> <HTML><HEAD>
      >->-> <META http-equiv=3DContent-Type content=3D"text/html; =
      >->-> charset=3Diso-8859-1">
      >->-> <META content=3D"MSHT ML 6.00.2900.2769" name=3DGENERATO R>
      >->-> <STYLE></STYLE>
      >->-> </HEAD>
      >->-> <BODY bgColor=3D#ffff ff>
      >->-> <DIV><FONT face=3DArial size=3D2>I have got all the results by using 2=20
      >->-> scanf().&nbsp; One is a dummy. &nbsp;I am also using double instead of =
      >->-> float.=20
      >->-> </FONT></DIV>
      >->-> <DIV><FONT face=3DArial size=3D2>Below are the results.&nbsp; I am =
      >->-> copying&nbsp; and=20
      >->-> paste from Notepad, so I hope I dont have HTML problem. </FONT></DIV>
      >->-> <DIV><FONT face=3DArial size=3D2>Regard s,</FONT></DIV>
      >->-> <DIV><FONT face=3DArial size=3D2>Khoon</FONT></DIV>
      >->-> <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
      >->-> <DIV>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial size=3D2>&nbsp; <FONT =
      >->-> color=3D#000080 ><STRONG>/*&nbsp;&nbsp;=2 0
      >->-> Roots of a Quadratic Equation.<BR>&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp; =
      >->-> 12.10.05&nbsp;= 20
      >->-> */</STRONG></FONT></FONT></DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 =
      >->-> size=3D2><STRON G></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>#include=20
      >->-> &lt;stdio.h&gt; <BR>#include &lt;stdlib.h&gt ;<BR>#include=2 0
      >->-> &lt;math.h&g t;</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>int main=20
      >->-> (void)</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>{<BR>&nbsp;in t =
      >->-> a; int b; int=20
      >->-> c; double x1; double x2; double E; int E1; double R; double I;double=20
      >->-> S;<BR>&nbsp;&nb sp;&nbsp; char q; char Y;</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>&nbsp;printf =
      >->-> ("Please key in=20
      >->-> the value of constant a,b and c for finding the roots of=20
      >->-> quadratic");<BR >&nbsp;&nbsp;&n bsp; printf ("equation ax%c+bx+c=3D0&n bsp; =
      >->->
      >->-> :",253);<BR>&nb sp;scanf ("%d%d%d", =
      >->-> &amp;a,&amp;b,& amp;c);<BR>&nbs p;&nbsp;&nbsp;= 20
      >->-> <BR>&nbsp;&nbsp ;&nbsp; E&nbsp; =
      >->-> =3D(b*b)-(4*a*c);<BR>&nb sp;<BR>&nbsp;&n bsp; if ( E=20
      >->-> &gt; 0) <BR>&nbsp;&nbsp ; {&nbsp;&nbsp;&n bsp;&nbsp; =
      >->-> <BR>&nbsp;&nbsp ;&nbsp; x1 =3D=20
      >->-> (float)(-b+sqrt(E))/(2*a);<BR>&nbsp ;&nbsp;&nbsp; x2 =3D=20
      >->-> (float)(-b-sqrt(E))/(2*a);</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 =
      >->-> size=3D2><STRON G>&nbsp;&nbsp;p rintf ("\nYour=20
      >->-> quadratic equation has two distinct real roots: x1=3D%1.6f=20
      >->-> ,x2=3D%1.6f",x1 ,x2);<BR>&nbsp; &nbsp; }<BR>&nbsp;&nbs p; <BR>&nbsp;&nbsp ; =
      >->-> else if (E=20
      >->-> =3D=3D 0) <BR>&nbsp;&nbsp ; {</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 =20
      >->-> size=3D2><STRON G>&nbsp;&nbsp;& nbsp;&nbsp;&nbs p; x1 =3D=20
      >->-> (float)(-b+sqrt(E))/(2*a);<BR>&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;=20
      >->-> <BR>&nbsp;&nbsp ; printf ("\nYour quadratic equation has two same:=20
      >->-> x1=3Dx2=3D%1.6f \n",x1);<BR>&nb sp;&nbsp; }<BR>&nbsp; <BR>&nbsp;&nbsp ; =
      >->-> else=20
      >->-> </STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>&nbsp;&nbsp;= 20
      >->-> {</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>&nbsp; printf =
      >->-> ("Your=20
      >->-> quadratic equation has two distinct imaginary roots.&nbsp; Do you want =
      >->-> to=20
      >->-> know");<BR>&nbs p; printf ("\nthe values of the imaginary roots=20
      >->-> (Y/N)?");<BR>&nbsp ;<BR>&nbsp; scanf=20
      >->-> ("%c",&amp;q );</STRONG>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp;&n=
      >->-> bsp;&nbsp;&nbsp ;&nbsp;=20
      >->-> &nbsp;<FONT color=3D#008080 ><STRONG>/*&nbsp;Dummy. &nbsp;The computer =
      >->-> jumps this=20
      >->-> scanf() */</STRONG></FONT></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>&nbsp; scanf=20
      >->-> ("%c",&amp;q );</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>&nbsp; printf =
      >->-> ("q =3D=20
      >->-> %c\n",q<FONT color=3D#008080 >)<FONT=20
      >->-> color=3D#000080 >;&nbsp;</FONT>&nbsp;&nbs p;&nbsp;&nbsp; &nbsp;/* Test=20
      >->-> statement*/</FONT></STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>&nbsp; if =
      >->-> ('Y'=3D=3Dq)<BR >&nbsp;=20
      >->-> {<BR>&nbsp;&nbs p;&nbsp;&nbsp;& nbsp; R =3D=20
      >->-> (float)-b/(2*a);<BR>&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp; =
      >->-> S=3Dabs(E);<BR> &nbsp;&nbsp; =20
      >->-> S=3Dsqrt(S);<BR >&nbsp;&nbsp; I =3D =
      >->-> S/(2*a);<BR>&nbsp ;&nbsp;&nbsp;&n bsp;&nbsp; printf=20
      >->-> ("\nThe imaginary roots are:\n");<BR>&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp; =
      >->-> printf ("=20
      >->-> x1=3D%1.6f + %1.6fi , x2=3D%1.6f - %1.6fi\n",R,I,R ,I);<BR>&nbsp; =
      >->-> }<BR>&nbsp;=20
      >->-> else<BR>&nbsp;& nbsp; printf ("Thank you for using this=20
      >->-> computer\n");<B R>}<BR>&nbsp; return 0;<BR>}</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>/* =
      >->-> RESULT<BR>Pleas e key in=20
      >->-> the value of constant a,b and c for finding the roots of =
      >->-> quadratic<BR>eq uation=20
      >->-> ax=B2+bx+c=3D0& nbsp; :3 4 1</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>Your quadratic =
      >->-> equation has=20
      >->-> two distinct real roots: x1=3D-0.333333 ,x2=3D-1.000000<BR>Pre ss any key =
      >->-> to continue=20
      >->-> */</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>/*Please key in =
      >->-> the value of=20
      >->-> constant a,b and c for finding the roots of quadratic<BR>eq uation=20
      >->-> ax=B2+bx+c=3D0& nbsp; :1 8 16</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>Your quadratic =
      >->-> equation has=20
      >->-> two same: x1=3Dx2=3D-4.000000<BR>Pre ss any key to continue =
      >->-> */</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>/*Please key in =
      >->-> the value of=20
      >->-> constant a,b and c for finding the roots of quadrati<BR>equ ation=20
      >->-> ax=B2+bx+c=3D0& nbsp; :4 2 5<BR>Your quadratic equation has two distinct =
      >->-> imaginary=20
      >->-> roots.&nbsp; Do you want to know<BR>the values of the imaginary roots=20
      >->-> (Y/N)?Y<BR>q =3D Y</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>The imaginary =
      >->-> roots=20
      >->-> are:<BR>x1=3D-0.250000 + 1.089725i , x2=3D-0.250000 - 1.089725i<BR>Pr ess =
      >->-> any key to=20
      >->-> continue*/</STRONG></FONT></DIV>
      >->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
      >->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>/*Please key in =
      >->-> the value of=20
      >->-> constant a,b and c for finding the roots of quadratic<BR>eq uation=20
      >->-> ax=B2+bx+c=3D0& nbsp; :4 2 5<BR>Your quadratic equation has two distinct =
      >->-> imaginary=20
      >->-> roots.&nbsp; Do you want to know<BR>the values of the imaginary roots=20
      >->-> (Y/N)?N<BR>q =3D N<BR>Thank you for using this computer<BR>Pre ss any key =
      >->-> to=20
      >->-> continue*/<BR>&nbsp;&nbsp ; <BR></STRONG></FONT></DIV></BODY></HTML>
      >->->
      >->-> ------=_NextPart_000_ 000E_01C5D424.9 4159240--
      >->->[/color]

      Comment

      • Red Dragon

        #18
        Re: Help. Where is my error?

        >>->-> any key to=20[color=blue][color=green]
        >>->-> continue*/</STRONG></FONT></DIV>
        >>->-> <DIV><FONT color=3D#000080 ><STRONG></STRONG></FONT>&nbsp;</DIV>
        >>->-> <DIV><FONT face=3DArial color=3D#000080 size=3D2><STRON G>/*Please
        >>key in =
        >>->-> the value of=20
        >>->-> constant a,b and c for finding the roots of quadratic<BR>eq uation=20
        >>->-> ax=B2+bx+c=3D0& nbsp; :4 2 5<BR>Your quadratic equation has two
        >>distinct =
        >>->-> imaginary=20
        >>->-> roots.&nbsp; Do you want to know<BR>the values of the imaginary
        >>roots=20
        >>->-> (Y/N)?N<BR>q =3D N<BR>Thank you for using this computer<BR>Pre ss any
        >>key =
        >>->-> to=20
        >>->-> continue*/<BR>&nbsp;&nbsp ; <BR></STRONG></FONT></DIV></BODY></HTML>
        >>->->
        >>->-> ------=_NextPart_000_ 000E_01C5D424.9 4159240--
        >>->->[/color][/color]


        Thank you Tim,
        I absolutely have no idea of the problem until I saw your post to me. Not
        even I dont like to read it, I am unable to read it.
        I had purposely sent myself a returned copy of the mail and it was not like
        this. The returned copy had not a single line of HTML code.
        I suppose why this problem arises is because only readers with Outlook
        Express get the mail in its perfect state. Others with different platform
        will get it all in HTML.
        Thanks for enlightening me.
        Regards,
        Khoon.



        Comment

        • Mark McIntyre

          #19
          Re: Help. Where is my error?

          On Tue, 18 Oct 2005 17:57:50 +0800, in comp.lang.c , "Red Dragon"
          <tskhoon@stream yx.com> wrote:
          [color=blue]
          >I dont quite understand the phrase "newline to terminate the line".[/color]

          How many keys do you press, when you supply user input value of 1? One
          key or two?
          --
          Mark McIntyre
          CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
          CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

          ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
          http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
          ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

          Comment

          • Red Dragon

            #20
            Re: Help. Where is my error?


            "Mark McIntyre" <markmcintyre@s pamcop.net> wrote in message
            news:5tnal1hg4f cv9frtlpsprdkuq d22h26vn6@4ax.c om...[color=blue]
            > On Tue, 18 Oct 2005 17:57:50 +0800, in comp.lang.c , "Red Dragon"
            > <tskhoon@stream yx.com> wrote:
            >[color=green]
            >>I dont quite understand the phrase "newline to terminate the line".[/color]
            >
            > How many keys do you press, when you supply user input value of 1? One
            > key or two?
            > --
            > Mark McIntyre[/color]

            2 keys. One for 1 and One for Enter.
            Can you kindly tell me is using 2 scanf() the best solution to the problem?
            What is a better method?
            Thanks
            Rgds,
            Khoon.




            Comment

            • Kevin Bagust

              #21
              Re: Help. Where is my error?

              Red Dragon wrote:[color=blue]
              > "Mark McIntyre" <markmcintyre@s pamcop.net> wrote in message
              > news:5tnal1hg4f cv9frtlpsprdkuq d22h26vn6@4ax.c om...[color=green]
              >>On Tue, 18 Oct 2005 17:57:50 +0800, in comp.lang.c , "Red Dragon"
              >><tskhoon@stre amyx.com> wrote:
              >>[color=darkred]
              >>>I dont quite understand the phrase "newline to terminate the line".[/color]
              >>How many keys do you press, when you supply user input value of 1? One
              >>key or two?
              >>--
              >>Mark McIntyre[/color]
              >
              > 2 keys. One for 1 and One for Enter.
              > Can you kindly tell me is using 2 scanf() the best solution to the problem?[/color]

              No, What would happen if the user entered more than one character on the
              line before entering Enter?
              [color=blue]
              > What is a better method?[/color]

              Have a look at the getchar() function. Use that to write a bit of code
              that will keep getting characters until it receives a new line.

              Kevin Bagust.

              Comment

              • Mark McIntyre

                #22
                Re: Help. Where is my error?

                On Wed, 19 Oct 2005 19:02:32 +0800, in comp.lang.c , "Red Dragon"
                <tskhoon@stream yx.com> wrote:
                [color=blue]
                >
                >"Mark McIntyre" <markmcintyre@s pamcop.net> wrote in message
                >news:5tnal1hg4 fcv9frtlpsprdku qd22h26vn6@4ax. com...[color=green]
                >> On Tue, 18 Oct 2005 17:57:50 +0800, in comp.lang.c , "Red Dragon"
                >> <tskhoon@stream yx.com> wrote:
                >>[color=darkred]
                >>>I dont quite understand the phrase "newline to terminate the line".[/color]
                >>
                >> How many keys do you press, when you supply user input value of 1? One
                >> key or two?
                >> --
                >> Mark McIntyre[/color]
                >
                >2 keys. One for 1 and One for Enter.[/color]

                .... so you see now where the newline comes from.
                [color=blue]
                >Can you kindly tell me is using 2 scanf() the best solution to the problem?
                >What is a better method?[/color]

                Personally I prefer to fgets() into a char array of known size, then
                parse the array via eg sscanf. I can then decide if there's still
                input waiting to be read, and if so I can empty it via repeated calls
                to say getchar.

                This is probably a FAQ (12.18, 12.20, 12.26 all seem relevant to this
                discussion, plus a few others in that area).
                --
                Mark McIntyre
                CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
                CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

                ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
                http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
                ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

                Comment

                • Red Dragon

                  #23
                  Re: Help. Where is my error?

                  I tried getchar() and found it has same effect as scanf()
                  Anyway thanks at lot.
                  Rgds,
                  Khoon.



                  Comment

                  • Keith Thompson

                    #24
                    Re: Help. Where is my error?

                    "Red Dragon" <tskhoon@stream yx.com> writes:[color=blue]
                    > I tried getchar() and found it has same effect as scanf()
                    > Anyway thanks at lot.
                    > Rgds,
                    > Khoon.[/color]

                    Surely you've been here long enough to know how to post a proper
                    followup using Google Groups. I've even seen you do it in this
                    thread.

                    Incidentally, saying that getchar() has the same effect as scanf() is
                    meaningless without context. They're obviously two different
                    functions, doing different things. If you'll show us some code, we
                    can suggest improvements.

                    --
                    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                    We must do something. This is something. Therefore, we must do this.

                    Comment

                    • Red Dragon

                      #25
                      Re: Help. Where is my error?


                      "Keith Thompson" <kst-u@mib.org> wrote in message news:lnwtk7k6s8 .fsf@nuthaus.mi b.org...[color=blue]
                      > "Red Dragon" <tskhoon@stream yx.com> writes:[color=green]
                      >> I tried getchar() and found it has same effect as scanf()
                      >> Anyway thanks a lot.
                      >> Rgds,
                      >> Khoon.[/color]
                      >
                      > Surely you've been here long enough to know how to post a proper
                      > followup using Google Groups. I've even seen you do it in this
                      > thread.[/color]

                      Sorry. What is Google Groups? I am using Outlook Express and Visual C++ platform.
                      [color=blue]
                      > Incidentally, saying that getchar() has the same effect as scanf() is
                      > meaningless without context. They're obviously two different
                      > functions, doing different things. If you'll show us some code, we
                      > can suggest improvements.[/color]

                      Thank you. Here is a program to illustrate my point.

                      /*Program to Demonstrate getchar() and scanf()*/
                      #include <stdio.h>

                      int main (void)
                      {
                      char a,b;

                      /*Section 1*/
                      printf("Enter a character > ");
                      scanf("%c",&a);
                      printf("a=%c\n" ,a);
                      printf("Enter another character > ");
                      getchar("%c",&b );
                      printf("b=%c\n" ,b);

                      /*section 2*/
                      printf("\nEnter a character > ");
                      scanf("%c",&a);
                      printf("a=%c\n" ,a);
                      printf("Enter another character > ");
                      scanf("%c",&b);
                      printf("b=%c\n" ,b);

                      /*section 3*/
                      printf("\nEnter a character > ");
                      scanf("%c",&a);
                      printf("a=%c\n" ,a);
                      printf("Enter another character > ");
                      scanf("%c",&b); /* Dummy */
                      scanf("%c",&b);
                      printf("b=%c\n" ,b);

                      return 0;
                      }
                      /*PRINT RESULT
                      Enter a character > a
                      a=a
                      Enter another character > b=¦

                      Enter a character > a
                      a=a
                      Enter another character > b=

                      Enter a character > a
                      a=a
                      Enter another character > b
                      b=b
                      Press any key to continue
                      */

                      You can see that I have divided the program into 3 sections.
                      1st section with getchar()
                      2nd section with single scanf()
                      3rd section with double scanf()
                      In the Printout Result, only 3rd Section with a Dummy performed perfectly.
                      BTW, Do you have HTML problem with my program above?
                      Regards and thank you very much.
                      Khoon.


                      Comment

                      • Keith Thompson

                        #26
                        Re: Help. Where is my error?

                        "Red Dragon" <tskhoon@stream yx.com> writes:[color=blue]
                        > "Keith Thompson" <kst-u@mib.org> wrote in message
                        > news:lnwtk7k6s8 .fsf@nuthaus.mi b.org...[color=green]
                        >> "Red Dragon" <tskhoon@stream yx.com> writes:[color=darkred]
                        >>> I tried getchar() and found it has same effect as scanf()
                        >>> Anyway thanks a lot.[/color]
                        >>
                        >> Surely you've been here long enough to know how to post a proper
                        >> followup using Google Groups. I've even seen you do it in this
                        >> thread.[/color]
                        > Sorry. What is Google Groups? I am using Outlook Express and Visual C++
                        > platform.[/color]

                        Sorry, my mistake.

                        groups.google.c om has a broken interface that encourages users to post
                        followups with no attributions or quoted text. I don't know why I
                        didn't check your article's headers before assuming you were using
                        Google Groups.

                        In general, posting a followup that doesn't quote any of the parent
                        article is considered rude.
                        [color=blue][color=green]
                        >> Incidentally, saying that getchar() has the same effect as scanf() is
                        >> meaningless without context. They're obviously two different
                        >> functions, doing different things. If you'll show us some code, we
                        >> can suggest improvements.[/color]
                        > Thank you. Here is a program to illustrate my point.
                        >
                        > /*Program to Demonstrate getchar() and scanf()*/
                        > #include <stdio.h>
                        >
                        > int main (void)
                        > {
                        > char a,b;
                        >
                        > /*Section 1*/
                        > printf("Enter a character > ");
                        > scanf("%c",&a);
                        > printf("a=%c\n" ,a);
                        > printf("Enter another character > ");
                        > getchar("%c",&b );
                        > printf("b=%c\n" ,b);[/color]

                        Ok, I was starting to write an explanation of what this code does when
                        I noticed this call:

                        getchar("%c",&b );

                        getchar() takes no arguments and returns an int value representing
                        the value of the input character or EOF. You have the required
                        "#include <stdio.h>" at the top of the program, so the compiler
                        knows this. Any working C compiler should give you an error message
                        on that line, or at least a warning.

                        Either you're running the compiler in a mode that causes it not to
                        display the error message (don't do that), or you're getting a warning
                        and ignoring it (don't do that), or the code you posted isn't the same
                        as the code you compiled (once again, don't do that).

                        If you're going to post code, you need to copy-and-paste the *exact*
                        code that you fed to the compiler. If you try to re-type it, you'll
                        make mistakes (I know I would), and there's no way we can guess which
                        errors are in the original code and which you introduced by re-typing
                        it.

                        If that really was the code you compiled, including the getchar() call
                        with too many arguments, you need to compile without turning off
                        diagnostic messages, and you need to fix any errors flagged by the
                        compiler.

                        [...]
                        [color=blue]
                        > BTW, Do you have HTML problem with my program above?[/color]

                        Not that I can see, but I think my newsreader sometimes quietly
                        renders HTML as plain text.

                        --
                        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                        We must do something. This is something. Therefore, we must do this.

                        Comment

                        • Red Dragon

                          #27
                          Re: Help. Where is my error?

                          [color=blue]
                          > In general, posting a followup that doesn't quote any of the parent
                          > article is considered rude.[/color]

                          Yes. I agree with that. [color=blue]
                          > [color=green][color=darkred]
                          >>> Incidentally, saying that getchar() has the same effect as scanf() is
                          >>> meaningless without context. [/color][/color][/color]

                          I was responding to the suggestion by Kevin Bagust to try using getchar() to solve the problem of scanf() being unable to read input character. As I learnt from Mark McIntyre, it could not read my character input because it was reading "newline' and jumped. This problem was demonstrated in my exhibit program as Section 1 using getchar() and section 2 using single scanf(), both failed to execute. Only when I used double scanf() was the problem solved.
                          [color=blue]
                          > Ok, I was starting to write an explanation of what this code does when
                          > I noticed this call:
                          >
                          > getchar("%c",&b );
                          >
                          > getchar() takes no arguments and returns an int value representing
                          > the value of the input character or EOF. You have the required
                          > "#include <stdio.h>" at the top of the program, so the compiler
                          > knows this. Any working C compiler should give you an error message
                          > on that line, or at least a warning.[/color]

                          I started C programing a month ago, self study on a book " A Structured Programming Approach Using C by Forouzan and Gilberg. I think it is very good.
                          Now I am on into Looping in Chapter 6, and I see getchar() is a topic in Chapter 7.
                          [color=blue]
                          > Either you're running the compiler in a mode that causes it not to
                          > display the error message (don't do that), or you're getting a warning
                          > and ignoring it (don't do that), or the code you posted isn't the same
                          > as the code you compiled (once again, don't do that).[/color]

                          When I compiled my code as shown in my previous program, I got 0 errors and 0 warnings.
                          [color=blue]
                          > If you're going to post code, you need to copy-and-paste the *exact*
                          > code that you fed to the compiler. If you try to re-type it, you'll
                          > make mistakes (I know I would), and there's no way we can guess which
                          > errors are in the original code and which you introduced by re-typing
                          > it.
                          >[/color]
                          When Tim Rentsch posted back to me what he had received, I was horrified by the load of gibberish HTML codes I had inadvertently created.
                          What I had earlier done was to copy from my Visual C++ platform and paste into Outlook Express. What I now do is to cut and paste into Notepad, and then cut from Notepad and paste into Outlook. In this way, I reckon I have killed all the HTML code. I did not do any retyping.
                          [color=blue][color=green]
                          >> BTW, Do you have HTML problem with my program above?[/color]
                          >
                          > Not that I can see, but I think my newsreader sometimes quietly
                          > renders HTML as plain text.[/color]

                          Thank you very much.
                          Regards,
                          Khoon.


                          Comment

                          • Dik T. Winter

                            #28
                            Re: Help. Where is my error?

                            In article <ln7jc7jo6y.fsf @nuthaus.mib.or g> Keith Thompson <kst-u@mib.org> writes:[color=blue]
                            > "Red Dragon" <tskhoon@stream yx.com> writes:[/color]
                            ....[color=blue][color=green]
                            > > /*Program to Demonstrate getchar() and scanf()*/
                            > > #include <stdio.h>
                            > >
                            > > int main (void)
                            > > {
                            > > char a,b;[/color][/color]

                            This is the first error. a and b should be ints.
                            --
                            dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
                            home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/

                            Comment

                            • Netocrat

                              #29
                              Re: Help. Where is my error?

                              On Fri, 21 Oct 2005 17:19:09 +0800, Red Dragon wrote:
                              [in reply to Keith Thompson][color=blue][color=green][color=darkred]
                              >>>> Incidentally, saying that getchar() has the same effect as scanf() is
                              >>>> meaningless without context.[/color][/color]
                              >
                              > I was responding to the suggestion by Kevin Bagust to try using getchar()
                              > to solve the problem of scanf() being unable to read input character.
                              > As I learnt from Mark McIntyre, it could not read my character input
                              > because it was reading "newline' and jumped.[/color]

                              Actually the point is that it was _not_ reading newline.
                              [color=blue]
                              > This problem was
                              > demonstrated in my exhibit program as Section 1 using getchar() and
                              > section 2 using single scanf(), both failed to execute. Only when I
                              > used double scanf() was the problem solved.[/color]

                              The dummy scanf is reading the newline (generated when you press
                              enter/return) that was not read by the first scanf.

                              [...][color=blue]
                              > I see getchar() is a topic in Chapter 7.[/color]

                              getchar() doesn't take arguments as scanf does, it returns a value.

                              Your code getchar("%c",&b ); should be rewritten b = getchar();

                              [...][color=blue]
                              > When I compiled my code as shown in my previous program, I got 0 errors
                              > and 0 warnings.[/color]

                              Find out how to invoke your Visual C++ compiler in ANSI or ISO C mode
                              (these may be abbreviated as C89/C90/C99). In such a mode it is required
                              to issue a diagnostic for your code.

                              [...][color=blue]
                              > When Tim Rentsch posted back to me what he had received, I was
                              > horrified by the load of gibberish HTML codes I had inadvertently
                              > created. What I had earlier done was to copy from my Visual C++ platform
                              > and paste into Outlook Express. What I now do is to cut and paste into
                              > Notepad, and then cut from Notepad and paste into Outlook. In this
                              > way, I reckon I have killed all the HTML code.[/color]

                              Some of your posts - even those without source code - still contain HTML,
                              including the one to which I'm replying and its predecessor. It is
                              likely that Outlook is generating it - check that Plain text is still
                              selected for News sending on the Send tab.

                              --

                              Comment

                              • Default User

                                #30
                                Re: Help. Where is my error?

                                Keith Thompson wrote:
                                [color=blue]
                                > "Red Dragon" <tskhoon@stream yx.com> writes:[/color]
                                [color=blue][color=green]
                                > > Sorry. What is Google Groups? I am using Outlook Express and
                                > > Visual C++ platform.[/color]
                                >
                                > Sorry, my mistake.[/color]


                                If you can get your newsreader to display custom message headers
                                (XanaNews does) then adding the User-Agent will help differentiate
                                Google from other posts.

                                Example:
                                User-Agent: G2/0.2




                                Brian

                                Comment

                                Working...