Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- void wyswietl_ciag(char* ciag)
- {
- unsigned i = 0;
- do
- {
- cout << ciag[i];
- ++i;
- }
- while(ciag[i] != '\0');
- }
- unsigned dlugosc_wyrazu(char* ciag)
- {
- unsigned i = 0;
- while(ciag[i] != '\0')
- ++i;
- return i;
- }
- char* wczytaj_tekst()
- {
- char znak = _getch();
- char* tekst = nullptr;
- if(static_cast<int>(znak) != 13)
- {
- cout << znak;
- tekst = new char[1];
- tekst[0] = znak;
- }
- else
- return nullptr;
- unsigned licznik = 1;
- znak = _getch();
- while(static_cast<int>(znak) != 13)
- {
- cout << znak;
- char* temp = new char[licznik + 1];
- for(unsigned i = 0; i < licznik; ++i)
- temp[i] = tekst[i];
- delete[] tekst;
- tekst = new char[licznik + 1];
- for(unsigned i = 0; i < licznik; ++i)
- tekst[i] = temp[i];
- delete[] temp;
- tekst[licznik] = znak;
- ++licznik;
- znak = _getch();
- }
- char* temp = new char[licznik + 1];
- for(unsigned i = 0; i < licznik; ++i)
- temp[i] = tekst[i];
- delete[] tekst;
- tekst = new char[licznik + 1];
- for(unsigned i = 0; i < licznik; ++i)
- tekst[i] = temp[i];
- delete[] temp;
- tekst[licznik] = '\0';
- cout << '\n';
- return tekst;
- }
- int main()
- {
- cout << "Napisz cos i zatwierdz klawiszem enter: ";
- char* napis = wczytaj_tekst();
- char ciag[5] = {'A', 'n', 'i', 'a', '\0'};
- wyswietl_ciag(ciag);
- cout << endl;
- wyswietl_ciag(napis);
- cout << endl << dlugosc_wyrazu(ciag) << endl;
- cout << dlugosc_wyrazu(napis) << endl;
- delete[] napis;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment