Segmentation Error : Command Arguments (argv)

前端 未结 2 1837
情书的邮戳
情书的邮戳 2021-01-24 08:11
#include
#include 
#include 
#include 
#include 
int main(int argc, string argv[])
{
  if (ar         


        
相关标签:
2条回答
  • 2021-01-24 08:27

    I believe the problem is in

     isdigit (argv[1])
    

    argv[1] is of type char *, but isdigit() expects an int.

    If you want to check whether the supplied argument is all-numerical value or not, you have to either

    • Loop over the elements in argv[n] and pass them one by one to isdigit() check.
    • use strtol() or similar to check for the validity.
    0 讨论(0)
  • 2021-01-24 08:29

    The error in on line 13, You need to do a

    ...
    13: if (isdigit (atoi(argv[1])) != 0)
    ...
    
    0 讨论(0)
提交回复
热议问题