CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: I think this is some bug..?

  1. #1
    Join Date
    Jun 2012
    Posts
    2

    I think this is some bug..?

    #include<conio.h>
    #include<stdio.h>
    #include<iostream.h>


    char char1[20];
    char char2[20];

    void GetChar1();
    void GetChar2();

    int main()
    {
    int ch=0;

    while(ch!=3)
    {
    cout<<"\nEnter ch: ";
    cin>>ch;
    if(ch==1)
    GetChar1();
    if(ch==2)
    GetChar2();
    }
    getch();
    return 0;
    }

    void GetChar1()
    {
    cout<<"Get Char1\n\n";
    gets(char1);

    cout<<"Char1: "<<char1;
    getch();
    }

    void GetChar2()
    {
    cout<<"Get Char2\n\n";
    gets(char2);
    cout<<"Char2: "<<char2;
    }
    -----------------------------------------------------------------------



    I am using DevC++ 4.9.9.6
    I have done C++ programming before. I never encountered this type of error. What happens is that..when i enter my choice as '1', it goes to the "GetChar1()" function...but doesnt execute the gets(char1) statement in that function. Same thing happens if i enter my choice as '2'.

    Please help

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: I think this is some bug..?

    See Why is my program ignoring my input request after the first iteration?

    PS. Please use code tags when posting code.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: I think this is some bug..?

    Quote Originally Posted by anindit View Post
    I am using DevC++ 4.9.9.6
    So why are you posting in the Visual C++ forum? You should have posted in the non-Visual C++ forum.
    I have done C++ programming before. I never encountered this type of error.
    First, this header:
    Code:
    #include <iostream.h>
    is not the correct ANSI C++ header. The correct header is
    Code:
    #include <iostream>
    That header you're using now is non-standard (it doesn't even exist in any version of Visual C++ that is less than 10 years old), and nothing guarantees that the header implements streams correctly, according to the ANSI standard.

    If you changed your header to <iostream> then we can tell you if there is a problem or not, as <iostream> must behave correctly, according to the ANSI/ISO standard. Otherwise, your <iostream.h> behaviour is acting as designed by the implementor and you can't complain.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 29th, 2012 at 05:05 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)