Creating an atoi function

后端 未结 5 1887
感情败类
感情败类 2021-01-19 04:03

I\'m attempting to create my own atoi function. With the following I\'m getting a return value of 0. Whatever I change the number variable within the function is what I get

5条回答
  •  深忆病人
    2021-01-19 04:28

    Some comments:

    int atoi_me(const char *numstring)...
    

    Better to use const type pointer, as you don't intend to modify string contents.

    int main()
    {
        char number[MAXSIZE]; // array of chars
        int num;
    
        printf("Please enter a number:\n");
        scanf("%s", number);     // enter a string, not a char
        num = atoi_me(number);   // pointer to char, not pointer to pointer
        printf("%d", num);
        return 0;
    }
    

提交回复
热议问题