Int len(char c[])
{ int m=0;
while(c[m++]);
return m-1
}
void main()
{char e[]=”Pro Tempore!”;
Cout<<(“\n%I”,len(E));
};
PASKAL' tilida copy funktsiyasi mavjud bo’lib, berilgan satrning, berilgan pozitsiyasidan boshlab berilgan sondagi simvollarini ajratib olishga imkon beradi. Shu funktsiyani C++ tilida qo’yidagicha ta'riflash mumkin:
Void copy(char a[], char b[], int k, int m)
{ int l;
for(int n=0; a[n]!=’\0’;n++);
if (k>m) {b[0]=’\0’;break};
if (k+m>n) l=n-k else l=m;
for(int i=0;i
}
Berilgan satrni teskariga aylantiruvchi funktsiya:
reverse(char s[]s) /* reverse string s in place */
int c, i, j;
for(i = 0, j = strlen(s) - 1; i < j; i++, j--)
c = s[i];
s[i] = s[j];
s[j] = c;
Keyingi misolimizda T qatorni S qator ohiriga o’lovchi STRCAT(S, T) funktsiyasini ko’rib chiqamiz:
strcat(s,t) /* concatenate t to end of s */
char s[], t[]; /* s must be big enough */
int i, j;
i = j = 0;
while (s[i] != '\0') / *find end of s */
i++;
while((s[i++] = t[j++]) != '\0') /*copy t*/
Dostları ilə paylaş: