1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

urgently need code to be corrected

Discussion in 'C++' started by kpsg25690, Sep 22, 2009.

  1. kpsg25690

    kpsg25690 New Member

    Joined:
    Aug 28, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    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(); 
    } 
     
  2. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    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.
     
  3. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Line 18: error: conio.h: No such file or directory
    Line 16: error: 'x' has not been declared
    compilation terminated due to -Wfatal-errors.
     
  4. kpsg25690

    kpsg25690 New Member

    Joined:
    Aug 28, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    I use turbo c++ not ansi c++ so i have to use <iostream.h> and not otherwise.
     
  5. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Check my 2nd answer please.
     
  6. kpsg25690

    kpsg25690 New Member

    Joined:
    Aug 28, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    the second answer is partially correct as x is not declared but i have to use <conio.h>
    for above mentioned reasons.....:happy:
     
  7. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    So it means, accept X, the rest is fine ;)
     
  8. kpsg25690

    kpsg25690 New Member

    Joined:
    Aug 28, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    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"
     
  9. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Could you please re-pate the code over here ?
     
  10. kpsg25690

    kpsg25690 New Member

    Joined:
    Aug 28, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    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(); 
    } 
     
  11. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Line 18: error: conio.h: No such file or directory
    t.cpp: In member function 'void str::concat(char*, char*)':
    Line 18: error: incompatible types in assignment of 'char*' to 'char [100]'
    compilation terminated due to -Wfatal-errors.
     
  12. kpsg25690

    kpsg25690 New Member

    Joined:
    Aug 28, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    that does not solve the problem.
    okay the error is detected but what am i supposed to do to correct it.
     

Share This Page