Реализуйте и протестируйте функцию void P2CStr(char *s); выполняющую преобразование строки s из Pascal-формата в формат С++. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Реализуйте и протестируйте функцию void P2CStr(char *s); выполняющую преобразование строки s из Pascal-формата в формат С++.

Heeelp

23rd Feb 2019, 8:00 AM
Matty
Matty - avatar
7 Answers
0
Yes, see below a code made in Pascal (free pascal compiler). The code simply dumps the content of a String in Pascal. Change the value of s variable, and pay attention to the first line. It'll be the exact count of "printable" chars in a string. var s: string; i: integer; begin s:='Mauricio'; for i:=0 to Length(s) do begin Write(Ord(s[i])); if(Ord(s[i])>32) then WriteLn('('+s[i]+')') else WriteLn(); end; end.
9th Mar 2019, 4:10 AM
Mauricio Martins
Mauricio Martins - avatar
+ 1
You're super!!!
9th Mar 2019, 4:18 AM
Matty
Matty - avatar
0
Я плохо понимаю по-русски но... Let's do in English Theoretically there's no difference in char array treatment from Pascal and C. But Pascal strings have a particular characteristic: the zero index is the length of the string. C strings don't bring the length, but the last char is a '\0'
9th Mar 2019, 1:40 AM
Mauricio Martins
Mauricio Martins - avatar
0
Thank you)
9th Mar 2019, 3:24 AM
Matty
Matty - avatar
0
Can you show me example of this code?
9th Mar 2019, 3:26 AM
Matty
Matty - avatar
0
In Other hand, the same code in C (C++ acts like). See the first char is a real char... not the count. And the last is always a \0 #include<stdio.h> #include<string.h> void main() { char *s="Mauricio"; int i; for(i=0;i<=strlen(s);i++) { printf("%d (%c)\n", s[i], (char)(s[i]<32?'_':s[i])); } }
9th Mar 2019, 4:17 AM
Mauricio Martins
Mauricio Martins - avatar
0
Спасибо!
9th Mar 2019, 4:31 AM
Mauricio Martins
Mauricio Martins - avatar