Consider the following:
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++;
}
I'm trying to malloc each time a word is taken in through scanf. However, I cannot seem to figure out why this does not work. I am getting errors:
warning: assignment makes integer from pointer without a cast
warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast