Hi everyone,
OK, so I want to read data in from a tab delimited file and then store part of it in a structure that i've built. The tab delimited file basically consists of 29 different lines of :
string <tab> string <tab> integer
It is the strings I want to read, compare and then store (I just want to store them at the moment in the node_data.name part.
The code will succesfully read the data nad print it straight to screen, but storing it and ten printing it is a different matter!
The code I've produced follows:
Code:
#include <stdio.h>
void main(void)
{
struct node_data /*This is the data structure that will contain*/{ /*the information regarding each node*/
char name;
int code_name;
int relax;
int value;
int previous_nodes[100];
};
struct node_data nodes[100];
int i;
char *sub_string;
FILE *stream;
if( (stream = fopen( "ukcities.txt", "r" )) != NULL )
{
if( fgets(nodes[0].name, 100, stream ) == NULL)
{
printf( "fgets error\n" );
}
else
{
printf("%s\n", strtok(nodes[0].name, " "));
while ( (sub_string=strtok(NULL, " ")) != NULL)
{
printf("%s\n", sub_string);
}
for(i=1;i<100;i++)
{
if( fgets( nodes[i].name, 100, stream ) == NULL)
break;
else
{
printf("%s\n", strtok(nodes[i].name, " "));
while ( (sub_string=strtok(NULL, " ")) != NULL)
{
printf("%s\n", sub_string);
}
}
}
fclose(stream);
}
}
}
The program compiles with the following errrors:
assignment makes pointer from integer without cast for different lines.
However, the program does compile succesfully.
I've been looking at trying different things for ages now, can someone please help me!!
Thankyou very much.
Ben