开发者

bash : input word becomes null with is inputed to a C binary [closed]

开发者 https://www.devze.com 2023-03-20 17:33 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post.
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

Improve this question

I have C binary program that receives one-word input. I have a file which contains a list of the words to be inputted to the program, one at a time.

so my script looks something like this"

while read line
do
  ./program  ${line}
done < myfile"

If I replace ./program with echo, every argument is printed properly. However, when I input it into the program via alias ($line), program receives blank. Please explain how to fix it and why开发者_如何学Go this is happening.


make a debug program to see what is going on...

int main (int argc, const char * argv[])
{

    printf("\n");
    // insert code here...
    for(int i = 0; i< argc ; i++)
    {
        printf("argc == %i, argv[%i]==%s\n",argc,i,argv[i]);
    }

    return 0;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消