+ 1

\376 on c

what is on output \376?

7th Feb 2020, 2:01 PM
Nicola
Nicola  - avatar
4 Antworten
+ 3
Nicola Esu char array a of size 1 is not good for taking word of length 4 or 6 as the space allocated is for 1 character only. You can change it to 6 to avoid any problem which may be caused due to pointer to memory which may be already allocated to some variable. For taking out last 2 characters you can use strlen(string) function to get length of string & then take out character at index (l-2) & (l-1) directly.
7th Feb 2020, 2:38 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
what is wrong on this code ? char a[1]; char i; char c; scanf("%s", a); for (i = 97; i <= 122; i++){ a[i] = a[0]; } for (i = 4; i <= 6; i++){ if(a[0] > i) { printf("%c", a[i]);} }else{ for(c = 97; c <= 122; c++){ a[c] = a[0];} for (c = 2; c <= 4; c++){ printf("%c", a[c]); } } } }
7th Feb 2020, 2:31 PM
Nicola
Nicola  - avatar
+ 1
this code must receive a word that can be either 4 or 6 characters long and must return the last 2 letters.
7th Feb 2020, 2:33 PM
Nicola
Nicola  - avatar
+ 1
why if I use it on xcode it gives me the last 2 on the 6 letter word! and on the 4 word it give: \ 240 program ended with exit code: 0?
7th Feb 2020, 3:00 PM
Nicola
Nicola  - avatar