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'.
Parse จำนวนเต็ม
เปลี่ยน string เช่น "-123" ให้เป็นตัวเลข -123, ด้วยมือ — งานที่ atoi ทำ อ่านเครื่องหมายนำหน้า - ที่อาจมีเพื่อกำหนดเครื่องหมาย แล้วสร้างค่าหลักหน่วยต่อหลักหน่วย: หลักใหม่แต่ละหลักหมายถึง 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)为了แปลง string ตัวเลข (ที่มี - นำหน้าได้) เป็นค่า integer โดยไม่ต้องใช้ฟังก์ชันจากไลบรารีอย่างเช่น atoi
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่