Advertisement
Chieffo

Operacje na char'ach

Oct 1st, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>//jest potrzebna ale nie operuje charami
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. char tekst[255];
  9. char napis[]="Ala ma kota";
  10. cout<<strstr (napis,"ma")<<endl; //wypisuje od wyrazu ma
  11. cout<<strlen(napis)<<endl; //ilośc znakow
  12. cout<<strcat(napis,"!")<<endl; //dodaje do łańcucha znaków !
  13. cout<<strncpy(tekst,napis,3)<<endl; //kopiuje 3 pierwsze znaki z napis do tekst
  14. cout<<strcmp(napis,tekst)<<endl; //porównuje jeżeli pierwszy jest dłuższy to zwraca 1 a jeżeli na odwrót to zwraca -1 jak 0 to są takie same
  15. cout<<strncmp(napis,tekst,3)<<endl<<endl; //porównuje 3pierwsze znaki obu tekstów i zwraca takie same wartości jak wyżej
  16. cout << tekst << ", " <<napis ;
  17. return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement