Problem Description
编写函数atoi(char s[])和read_line(char str[], int n),将字符串转换为对应数值的整数
测试程序为:
#include <stdio.h>
#include <ctype.h>
#define STR_LEN 20
int read_line(char str[], int n); //n为字符串的长度,返回实际读入的字符个数
int atoi(char s[]);
int main()
{
char str[STR_LEN + 1];
read_line(str, STR_LEN);
printf("%d\n", atoi(str));
return 0;
}
/* 你的代码将被嵌在这里 */
Input Description
在一行中输入一个字符串。
Output Description
输出字符串对应数值的整数。
Sample Input
+12345
Sample Output
12345
答案:
#include <stdio.h>
#include <ctype.h>
#define STR_LEN 20
int read_line(char str[], int n); //n为字符串的长度,返回实际读入的字符个数
int atoi(char s[]);//将字符串转换为整型值。
int main()
{
char str[STR_LEN + 1];
read_line(str, STR_LEN);
printf("%d\n", atoi(str));
return 0;
}
int read_line(char str[], int n)
{
gets(str);
}
Problem Description
编写函数atoi(char s[])和read_line(char str[], int n),将字符串转换为对应数值的整数
测试程序为:
#include <stdio.h>
#include <ctype.h>
#define STR_LEN 20
int read_line(char str[], int n); //n为字符串的长度,返回实际读入的字符个数
int atoi(char s[]);
int main()
{
char str[STR_LEN + 1];
read_line(str, STR_LEN);
printf("%d\n", atoi(str));
return 0;
}
/* 你的代码将被嵌在这里 */
Input Description
在一行中输入一个字符串。
Output Description
输出字符串对应数值的整数。
Sample Input
+12345
Sample Output
12345
答案:
#include <stdio.h>
#include <ctype.h>
#define STR_LEN 20
int read_line(char str[], int n); //n为字符串的长度,返回实际读入的字符个数
int atoi(char s[]);//将字符串转换为整型值。
int main()
{
char str[STR_LEN + 1];
read_line(str, STR_LEN);
printf("%d\n", atoi(str));
return 0;
}
int read_line(char str[], int n)
{
gets(str);
}