Storing Info From file into Array of structs

This is a discussion on Storing Info From file into Array of structs within the C Programming forums, part of the General Programming Boards category; >> storm[g].name is my destination within my struct, but my source is an input file, so that makes me think ...

  1. #16
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> storm[g].name is my destination within my struct, but my source is an input file, so that makes me think my second argument is wrong.

    I can't see the declaration for 'name' so it's not clear, but assuming it's a char buffer with the same size as the struct member, you are doing it correctly (a 1000 times). Just be sure the variable 'name' isn't being used elsewhere in the program for some other purpose and you should be fine.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #17
    Registered User
    Join Date
    Jun 2009
    Posts
    28
    thanks...i got it this part figured out using the strcpy...it ended up looking like this...


    Code:
    while((i=fscanf(fp,"%10s %i %i %f", name, &lattitude, &longitude,&force))!=EOF){
    		
    		
    	
    		for(g=0;g<21;g++){
    	
    		strcpy(storm[j].name,name);
    		}
    		storm[j].lattitude = lattitude ;
    		storm[j].longitude = longitude;
    		storm[j].force = force;
    		j++;
    		}

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read a file (binary) into an array of structs
    By Separ in forum C Programming
    Replies: 3
    Last Post: 04-14-2009, 10:09 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

Tags for this Thread


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