Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   urgently need code to be corrected (http://www.go4expert.com/forums/urgently-code-corrected-t19506/)

kpsg25690 22Sep2009 15:17

urgently need code to be corrected
 
i need to get this code debugged ....
thank you in advance..:confused:

Code:

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
 
class str
{
public:
char s[100];
str()
{;}
str(char *ch)
    {
    strcpy(s,ch);
    }
void concat(x,y)
    {
    s=strcat(x,y);
    }
void showdata(ch)
    {
    puts(ch);
    }
void getdata()
    {
    cout<<"\nEnter the string:";
    gets(s);
    }
};
 
void main()
{
clrscr();
char a[100],b[100],ch[100];
cout<<"\n\t\t\tCreating an uninitialised object";
str c,c2;
puts(c.s);
cout<<"\n\t\t\tCreating an object with string constants";
str c1("Hello World");
puts(c1.s);
cout<<"\nEnter two strings:";
gets(a);
gets(b);
c2.s=c2.concat(a,b);
cout<<"\nEnter a string to be displayed:";
gets(ch);
c.showdata(ch);
getche();
}


naimish 22Sep2009 15:21

Re: urgently need code to be corrected
 
iostream.h, line 1: catastrophic error: #error directive:
<iostream.h> is not a Standard header, use <iostream> instead.
Note that when you change this header name, that identifiers such as
"cout" and "endl" will no longer work, as they are in namespace
"std", so use be "std::cout" and "std::endl" respectively.

1 catastrophic error detected in the compilation of "ComeauTest.c".
Compilation terminated.

naimish 22Sep2009 15:23

Re: urgently need code to be corrected
 
Line 18: error: conio.h: No such file or directory
Line 16: error: 'x' has not been declared
compilation terminated due to -Wfatal-errors.

kpsg25690 22Sep2009 15:27

Re: urgently need code to be corrected
 
Quote:

Originally Posted by naimish (Post 57785)
iostream.h, line 1: catastrophic error: #error directive:
<iostream.h> is not a Standard header, use <iostream> instead.
Note that when you change this header name, that identifiers such as
"cout" and "endl" will no longer work, as they are in namespace
"std", so use be "std::cout" and "std::endl" respectively.

1 catastrophic error detected in the compilation of "ComeauTest.c".
Compilation terminated.

I use turbo c++ not ansi c++ so i have to use <iostream.h> and not otherwise.

naimish 22Sep2009 15:28

Re: urgently need code to be corrected
 
Check my 2nd answer please.

kpsg25690 22Sep2009 15:31

Re: urgently need code to be corrected
 
Quote:

Originally Posted by naimish (Post 57791)
Check my 2nd answer please.

the second answer is partially correct as x is not declared but i have to use <conio.h>
for above mentioned reasons.....:happy:

naimish 22Sep2009 15:32

Re: urgently need code to be corrected
 
So it means, accept X, the rest is fine ;)

kpsg25690 22Sep2009 15:36

Re: urgently need code to be corrected
 
replacing x and y by char *x and char *y solved that problem but now the strcat function shows the error
line 18:"Lvalue required"
line 44:"Not an allowed type"

naimish 22Sep2009 15:37

Re: urgently need code to be corrected
 
Could you please re-pate the code over here ?

kpsg25690 22Sep2009 15:40

Re: urgently need code to be corrected
 
here you go..:wacky:
Code:

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
 
class str
{
public:
char s[100];
str()
{;}
str(char *ch)
    {
    strcpy(s,ch);
    }
void concat(char *x,char *y)
    {
    s=strcat(x,y);
    }
void showdata(char *ch)
    {
    puts(ch);
    }
void getdata()
    {
    cout<<"\nEnter the string:";
    gets(s);
    }
};
 
void main()
{
clrscr();
char a[100],b[100],ch[100];
cout<<"\n\t\t\tCreating an uninitialised object";
str c,c2;
puts(c.s);
cout<<"\n\t\t\tCreating an object with string constants";
str c1("Hello World");
puts(c1.s);
cout<<"\nEnter two strings:";
gets(a);
gets(b);
c2.s=c2.concat(a,b);
cout<<"\nEnter a string to be displayed:";
gets(ch);
c.showdata(ch);
getche();
}



All times are GMT +5.5. The time now is 23:26.