Pages

Sunday, April 20, 2025

Input Char Arrays in C++

 #include <iostream>

#include <cstring>

using namespace std;



int main() {

    // char word[10];

    // cin >> word; //ignore whitespace

    

    // cout << "your word was : " << word << endl;

    // cout << "length : " << strlen(word) << endl;

    

    char sentence[30];

    cin.getline(sentence, 30, '*');

    

    cout << "your word was : " << sentence << endl;

    cout << "length : " << strlen(sentence) << endl;


    return 0;

}

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...