Advertisement
Dani_info

Tema 26.03.2019

Mar 25th, 2019
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char c[20];
  9.     cout<<"Introdu sirul:"<<endl; cin.get(c, 20);
  10.     char x;
  11.     cout<<"Introdu caracterul"<<endl; cin>>x;
  12.     char *p;
  13.     p=strchr(c, x);
  14.     int nrap=0;
  15.     while (p){
  16.         cout<<"Pozitia "<<p-c<<endl;
  17.         nrap++;
  18.         p=strchr(++p, x);
  19.     }
  20.     if (nrap) cout<<"Caracterul apare de "<<nrap<<" ori"<<endl;
  21.     else cout<<" Caracterul nu apare"<<endl;
  22.     return 0;
  23. }
Advertisement
RAW Paste Data Copied
Advertisement