Parse an integer · تحليل عدد صحيح
Parse an integer
Turn a string like "-123" into the number -123, by hand — the job atoi does. Read an optional leading - to fix the sign, then build the value digit by digit: each new digit means result = result * 10 + digit. A character converts to its digit value with c - '0'.
تحليل عدد صحيح
حوّل سلسلة نصية مثل "-123" إلى الرقم -123، يدويًا — وهي المهمة التي تقوم بها atoi. اقرأ إشارة leading اختيارية - لتحديد الإشارة، ثم بِن القيمة رقماً برقم: كل رقم جديد يعني result = result * 10 + digit. يُحوّل الحرف إلى قيمته الرقمية باستخدام c - '0'.
Complete int parse_int(const char *s) that converts a string of digits (with an optional leading -) to its integer value, without using library functions like atoi. · أكمل int parse_int(const char *s) لتحويل سلسلة من الأرقام (مع leading - اختياري) إلى قيمتها العددية الصحيحة، دون استخدام دوال مكتبة مثل atoi.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.