「変数を収集できません」とはどういう意味ですか?どうすれば修正できますか?デバッガは値を報告しません。"変数を収集できません"?
私はargv
を変更して再配置するつもりだ
write_argument2(argc, * argv, * string[0]);
私の関数を呼び出すしようとしています。私の変数string
はchar **string[100][100];
で、理想的ではないかもしれません。文字列変数には、新しい引数でargv
を更新する予定です。
void write_argument2(int argc, char argv[], char *string[]) {
int j = 0;
for (j = 0; j < argc; j++) {
if (argv[j])
string[j] = strdup(&argv[j]);
}
}
しかし、私は何か間違ったことをやったし、それがクラッシュします。エラーは「変数を収集できません」と表示され、strdup
のセグメントエラーが発生します。
私もコンパイルもセグメンテーション違反となり、以下を試してみました:* string[j] = * strdup(& argv[j]);
GDBは言う:
GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./shell...done.
(gdb) run
Starting program: /home/dac/ClionProjects/shell2/openshell/shell
'PATH' is set to /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin.
$ ls
Program received signal SIGSEGV, Segmentation fault.
0x0000000000403b1a in write_argument2 (string=<optimized out>, argv=<optimized out>,
argc=<optimized out>) at main.c:147
147 string[j] = strdup(&argv[j]);
(gdb)
は、私が代わりにstrcpy
を使用するか、いくつかの宣言を変更する必要がありますか?
は 'strlenを(のstrdup(ARGV [J]))'文字列の長さである 'ARGV [J]'、間違っている、それは数ではありません配列内の文字列。関数を呼び出すコードを投稿してみませんか? – fluter
'string = write_argument2(argc、argv);'は関数を呼び出すコードです。 – Montao
@Montaoは私のテストプログラムを見て、それは私のために働く。 – fluter