segmentation fault checking user arguments c

后端 未结 3 1933
天涯浪人
天涯浪人 2021-01-27 22:52

I am trying to validate user input from the command line with argc and argv but am running into a segmentation fault and am not sure why.

I want to validate the user has

3条回答
  •  死守一世寂寞
    2021-01-27 23:11

    As others have noted string is not a base type. However since you are getting results in one case your segmentation fault has to do with the atoi on argv 1. In c arrays are 0 based so you're trying to convert uninitialized memory. Use the argc test before the atoi.

提交回复
热议问题