Thread: Why not debugging?

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    99

    Why not debugging?

    It says

    Code:
    main.cpp:15:26: error: invalid conversion from ‘char’ to ‘std::basic_istream::char_type* {aka char*}’ [-fpermissive]     cin.get(buffer2, SIZE);

    Code:
    #include <iostream>
    using namespace std;
    
    
    int main(){
        
        const int SIZE{80};
        char buffer1{SIZE};
        char buffer2{SIZE};
        
        cout << "Enter a sentence:\n";
        cin >> buffer1;
        
        cout << "\nThe string read with cin was:\n"  << buffer1  << "\n\n";
        
        cin.get(buffer2, SIZE);
        
        cout  << "The string read with cin.get was:\n"  << buffer2  << endl;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Perhaps you meant to create buffer1 and buffer2 as C-strings instead of as single characters?

    Lines 8 and 9 are creating single characters with the initial value of 80, not C-strings with a size of 80.

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    99
    Right, it was
    Code:
     [] not {}
    Quote Originally Posted by jimblumberg View Post
    Perhaps you meant to create buffer1 and buffer2 as C-strings instead of as single characters?

    Lines 8 and 9 are creating single characters with the initial value of 80, not C-strings with a size of 80.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I'd also suggest you start using C++ strings instead of the C-strings as a C++ string is much safer, and IMO easier to use.

  5. #5
    Registered User
    Join Date
    Dec 2019
    Posts
    99
    Quote Originally Posted by jimblumberg View Post
    I'd also suggest you start using C++ strings instead of the C-strings as a C++ string is much safer, and IMO easier to use.
    Ok, thank you. I really appreciate it.

  6. #6
    Registered User
    Join Date
    Aug 2021
    Posts
    1

    Post

    Debugging is a process in which you find the cause of a bug. The process involves tracing what is happening and understanding the problem.
    In C programming, debugging is not as easy as in other programming languages such as Java or Python. This is because C has no direct way of finding out where a program went wrong and it cannot be done by running the program.
    C cannot be debugged by stepping through code either because there are no breakpoints that can be set at specific locations or because if there are breakpoints, they will not function correctly. However, it does have some tools that can help with debugging. These tools include printf() , assert() , and check() .
    Last edited by Salem; 08-08-2021 at 04:18 AM. Reason: Removed spam link

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C, need debugging help
    By Theta Zero in forum C Programming
    Replies: 15
    Last Post: 02-16-2011, 10:49 PM
  2. Need help debugging this
    By We'reGeeks in forum C Programming
    Replies: 14
    Last Post: 01-08-2011, 09:41 PM
  3. Debugging
    By cecil_rabmere in forum C Programming
    Replies: 2
    Last Post: 06-13-2008, 03:36 PM
  4. Debugging help
    By iitb.ankit in forum C Programming
    Replies: 4
    Last Post: 06-04-2006, 07:20 AM
  5. debugging
    By Ssfccsh in forum C++ Programming
    Replies: 10
    Last Post: 03-01-2004, 12:20 AM

Tags for this Thread