Results 1 to 4 of 4
Thread: C++ : 2- ?
Hybrid View
-
19th November 2012 14:38 #1Registered 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.
-
19th November 2012 15:21 #2
, .
, "code" -
:
nov[0]=star[0]; , strncpy. , strncopy '\0' . "nov" , strncpy.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[1]=star[strlen(star)-1];
nov[2]='\0'; strncpy
, - , . , 'star' .
, 'x' , 'x' , '\0' , . , .
P.S. , - :
&star[strlen(star)-1] "&" ( ) "star" ,Code:int main(){ char star[10]; char nov[3]; cout<<"vyvedete string: "; cin>>star; strncpy(nov, star, 1); strcat(nov, &star[strlen(star)-1]); }Last edited by KaloyanP; 19th November 2012 at 15:40.
D80; 50/1.8D; Tamron 70-300; 18-55 VR;
-
20th November 2012 10:13 #3Registered User
Join Date: Nov:2009
Location:
Posts: 83
, :
.Code:strncpy(nov,star,1); char x[] ={star[strlen(star)-1],'\0'}; strcat(nov,x);
-
20th November 2012 12:30 #4
, , , . "", :
, strlen(star), . star[-1], -, .Code:char nov[3] = {star[0], star[strlen(star)-1], 0};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




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in