我正在使用结构类型。我从我自己的文件中提取了一行,上面写着“地狱犬守卫冥河”。当我尝试打印出来时,只打印出字母“c”。我不知道为什么会这样。
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned int uint;
struct wordType
{
char word[80];
uint count;
};
struct wordType words[10];
int main( void ) {
FILE * inputFile;
char * line = NULL;
size_t len = 0;
ssize_t read;
uint index;
inputFile = fopen( "input.txt", "r");
if( inputFile == NULL )
{
printf( "Error: File could not be opened" );
/*report failure*/
return 1;
}
index = 0;
while( ( read = getline( &line, &len, inputFile ) ) != -1 )
{
printf( "%s\n", line );
*words[index].word = *line;
printf("line = %s\n", (words[index].word) );
}
free( line );
return 0;
}