Hi everyone, right, I have a program that reads char strings in from a tab delimited file, I can do this. I now want the program to store part of this data(the char strings) as one of the fields in a data structure, there is an array of these data strutures. The program must also recognise when a duplicate char string has been read in, and hence not store this value. My code to date follows:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
struct node_data /*This is the data structure that will contain */
{ /*the information regarding each node */
char name[30];
int code_name;
int relax;
int value;
int previous_nodes[100];
};
int i, j, k, l, m;
char *sub_string;
char line[100];
FILE *stream;
struct node_data nodes[100]; /*Declaring an array of nodes with 100 spaces*/
for(k=1;k<100;k++)
{
for(l=0;l<30;l++)
{
nodes[k].name[l] = NULL;
}
}
if( (stream = fopen( "ukcities.txt", "r" )) != NULL )
{
if( fgets(line, 100, stream ) == NULL)
{
printf( "fgets error\n" );
}
else
{
printf("%s\n", strtok(line, " "));
while ( (sub_string=strtok(NULL, " ")) != NULL)
{
printf("%s\n", sub_string);
}
for(i=1;i<100;i++)
{
if( fgets(line, 100, stream ) == NULL)
break;
else
{
printf("%s\n", strtok(line, " "));
while ( (sub_string=strtok(NULL, " ")) != NULL)
{
printf("%s\n", sub_string);
}
}
}
}
fclose(stream);
}
}
Thankyou!!