Passing Linux boot opts to Init

回眸只為那壹抹淺笑 提交于 2019-12-06 12:47:20

I don't know C, but I think where is int i; (line 4) should be int i = 0;. If I am wrong, add a comment to my answer and I will delete it.

Edit: you could also do i = 0 in the for loop: for(i = 0; i < argc; i++).

You need to initialize i to 0 as Artur said. If you dont the value of i is whatever happend to be in the memory at the time the program ran. Sometimes it will work, others i would be >= argc and the loop would be skipped, the worst case i is negative and your program segfaults.

Also in python try:

# i do not need to be initialized
# for counting xrange is better, it does not built the whole list on memory
for i in xrange(1, len(sys.argv)):
    print("arg[%d] - %s" % (i, sys.argv))
    # i do not need to be incremented manually
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!