考虑以下:
typedef struct wordType
{
char word;
uint count;
};
int main( void )
{
typedef struct wordType * WORD_RECORD;
WORD_RECORD arrayOfWords = malloc(10 * sizeof( WORD_RECORD) );
FILE * inputFile;
char temp[50];
uint index;
inputFile = fopen( "input.txt", "r");
while( fscanf( inputFile, "%s", temp) == 1 )
{
printf("%s\n", temp );
arrayOfWords[index].word = malloc( sizeof(char)*(strlen(temp) + 1 ));
strcpy( arrayOfWords[index].word, temp );
}
index++;
}
每次通过scanf输入一个单词时,我都在尝试进行malloc。但是,我似乎无法弄清楚为什么这不起作用。我收到错误:
warning: assignment makes integer from pointer without a cast
warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast