-
August 29th, 2012, 03:50 AM
#1
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
-
August 29th, 2012, 04:11 AM
#2
Re: I think this is some bug..?
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
-
August 29th, 2012, 05:02 AM
#3
Re: I think this is some bug..?
Originally Posted by anindit
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|