0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C】文字を書き換えするときにエラーと対処法

Last updated at Posted at 2025-01-15

なんか地味なエラーが出てきました.

test.c: In function 関数名:
test.c:49:48: error: assignment to 'char' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
   49 |             assembly_buf[strlen(assembly_buf)] = "\0";

該当箇所

test.c
char buf[1024];
Read_Line(path,buf,search(path,div_buf,max),1024);
//\n消去
assembly_buf[strlen(assembly_buf)-1] = "\0";

char*charに入っている的なエラーです。

エラーを治したプログラム

test.c
char buf[1024];
Read_Line(path,buf,search(path,div_buf,max),1024);
//\n消去
buf[strlen(buf)-1] = '\0';

これは

buf[strlen(buf)-1] = '\0';

の部分の'\0'"\0"から'\0'に代わっています。
どうやら'\0'は文字のリストではなく文字単体で
"\0"は文字のリストで文字単体ではないようです.

pythonでは同じだったのでこんなエラーは意外でした

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?