"" に関する原因と対処

このコンパイルエラーの原因と対処に関して説明します。

スポンサード リンク

Microsoft Visual C++にて以下のソースでコンパイルエラーが発生します:

コンパイルエラーメッセージ:
error C3750: '=': 属性リストに予期しないトークンがあります

ソース(バグ有り):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char test_string[[ = "abcde ";
//文字列の末尾の場所を調べる
int i = strlen(test_string);
//文字列の一番後ろから前に空白を探す
while ( --i >= 0 && test_string[i] == ' ' )
test_string[i+1] = '\0';
printf("%s" , test_string);
return 0; }


原因:


対処:


ソース(修正済み):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char test_string[] = "abcde ";
//文字列の末尾の場所を調べる
int i = strlen(test_string);
//文字列の一番後ろから前に空白を探す
while ( --i >= 0 && test_string[i] == ' ' )
test_string[i+1] = '\0';
printf("%s" , test_string);
return 0; }

スポンサード リンク



[コンパイルエラーコード、メッセージに戻る]