Advertisement
rotti321

Exemple pr siruri de char

Nov 17th, 2021
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main() {
  6.     char ch,*p, a[100]="crocodil", b[100]="hipopotam", dr[100]={}, st[100]={};
  7.     int nr=0,x, cif;
  8.    
  9.     if((ch>='a' && ch<='z')||(ch>='A' && ch<='Z'))  ///isalpha
  10.     /*
  11.     ///Transforma un int  --> sir de caractere
  12.     strcpy(a,"");
  13.    
  14.     cin>>x;
  15.     if(x==0){
  16.         a[0]='0';
  17.         a[1]='\0';
  18.     }
  19.     while(x!=0){
  20.         cif=x%10;
  21.         x=x/10;
  22.         st[0]=cif+'0';
  23.         st[1]='\0';
  24.         strcpy(dr,a);
  25.         strcat(st,dr);
  26.         strcpy(a,st);
  27.     }
  28.     cout<<a;
  29.     /*
  30.    
  31.     cin.getline(a,100);
  32.     cin.getline(b,100);
  33.    
  34.    
  35.     ////Trece Mishu la Sport? da/nu
  36.     p=strtok(a," ,.");
  37.     while(p!=NULL){
  38.         if(p[0]>='0' && p[0]<='9'){
  39.             for(int i=0;i<strlen(p);i++){
  40.                 nr=nr*10+p[i]-'0';
  41.             }
  42.         }
  43.         p=strtok(NULL," .");
  44.     }
  45.     if(nr>=50){
  46.         cout<<"Da";
  47.     }
  48.     else{
  49.         cout<<"Nu";
  50.     }
  51.  
  52.    
  53.    
  54.    ///abCd ---> ABCD
  55.     for(int i=0;i<strlen(a);i++){
  56.         if(a[i]>='a' && a[i]<='z'){ ///isalpha(a[i])
  57.             a[i]=a[i]-('a'-'A');
  58.         }
  59.     }
  60.     cout<<a;
  61.     /*
  62.    
  63.    
  64.     ///Sa se copieze in sirul a primele 4 caractere din b
  65.     p=strstr(a,b); ///p = a + poz
  66.     if(p!=NULL){
  67.         cout<<"ultima aparitie este pe poz:"<<p-a<<endl;
  68.         cout<<p;
  69.     }
  70.     else{
  71.         cout<<"nu exista";
  72.     }
  73.     //cout<<endl<<"abc";
  74.     */
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement