は、私は、あなたがファイルからだけではなく、1文字を読んで、その次の例を見てしようとしているとします
#define STR_SIZE 10
// STR_SIZE defines the maximum number of characters to be read from file
int xp;
char str[STR_SIZE + 1] = { 0 }; // here all array of char is filled with 0
// +1 in array size ensure that at least one '\0' char
// will be in array to be the end of string
int strCnt = 0; // this is the conter of characters stored in the array
while (1) {
xp = fgetc(f);
char xpchar = xp;
//convert xpchar into a string
str[strCnt] = xpchar; // store character to next free position of array
strCnt++;
if (strCnt >= STR_SIZE) // if array if filled
break; // stop reading from file
}
そして、あなたのファイルポインタ変数の名前 - filename
は奇妙に見える(filename
は良い名前ですファイルの名前を格納する文字列変数が、fgetc
とgetc
必要FILE *
)のために、ので、あなたのプログラムであなたのようなものがあることを確認します
FILE * f = fopen(filename, "r");
またはfilename
の名前を変更する上だと思うが。
'char'配列を作成し、そこに格納し始めます....実際にあなたの質問は何ですか? –
文字列は、末尾にヌル文字を持つ単なる文字配列です。 – Barmar
私は印刷できます。 printf( "%c"、xpchar); %sを使用したいと思います。 –