Storing in structure

This is a discussion on Storing in structure within the C Programming forums, part of the General Programming Boards category; Hi everyone, right, I have a program that reads char strings in from a tab delimited file, I can do ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    12

    Storing in structure

    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!!

  2. #2
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    You already create the same post with the same thing, All you need is ask all in that post. Stop spaming.
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  3. #3
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Don't multi post.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 10:28 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Storing in structure
    By bennyboy in forum C Programming
    Replies: 1
    Last Post: 02-26-2005, 06:14 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. Storing Data in a Structure
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-28-2001, 06:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21