Results 1 to 4 of 4

Thread: C++ : 2- ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Nov:2009
    Location:
    Posts: 83

    C++ : 2- ?

    , . , char[n], 2- . strncpy(nov,star,1), -
    1. k=strlen(star);
    2. char x; ( ) - x=star[k-1];
    3. strcat(nov,x); "invalid conversion from char to const char.'"

    , : char x; char nov[3]; char star[10];
    char x char x[3], - strcat(nov,x) , k=strlen(star) ...

    , , :

    Code:
    using namespace std;
    char star[10];
    char nov[3];
    char x;
    int k;
    
    
    int main(){
        cout<<"vyvedete string: ";  cin>>star;
        
        strncpy(nov,star,1);
        k=strlen(star);
        x=star[k-1];
        strcat(nov,x);
    
    }
    .. , , :
    1. char x;
    2. : x=star[k-1]; : char x[] ={star[(k-1)],'\0'};
    .. ,
    Last edited by JuneK; 20th November 2012 at 10:00.

  2. #2
    a.k.a. Kal KaloyanP's Avatar
    Join Date: Dec:2005
    Location: UK
    Posts: 3,750
    Quote Originally Posted by JuneK View Post
    , . , char[n], 2- .
    , .

    , "code" -

    :
    Code:
    int main(){
    char star[10];
    char nov[3];
    cout<<"vyvedete string: "; cin>>star;
    
    nov[0]=star[0];//   
    nov[1]=star[strlen(star)-1];
    nov[2]='\0';//   
    
    }
    nov[0]=star[0]; , strncpy. , strncopy '\0' . "nov" , strncpy.

    nov[1]=star[strlen(star)-1];

    nov[2]='\0'; strncpy

    , - , . , 'star' .

    , 'x' , 'x' , '\0' , . , .


    P.S. , - :
    Code:
    int main(){
    char star[10];
    char nov[3];
    cout<<"vyvedete string: "; cin>>star;
    
    strncpy(nov, star, 1);
    strcat(nov, &star[strlen(star)-1]);
    }
    &star[strlen(star)-1] "&" ( ) "star" ,
    Last edited by KaloyanP; 19th November 2012 at 15:40.
    D80; 50/1.8D; Tamron 70-300; 18-55 VR;

  3. #3
    Registered User
    Join Date: Nov:2009
    Location:
    Posts: 83
    , :
    Code:
    strncpy(nov,star,1);
    char x[] ={star[strlen(star)-1],'\0'};
    strcat(nov,x);
    .

  4. #4
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    , , , . "", :
    Code:
    char nov[3] = {star[0], star[strlen(star)-1], 0};
    , strlen(star), . star[-1], -, .
    Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |