Random behaviour structs please explain

This is a discussion on Random behaviour structs please explain within the C Programming forums, part of the General Programming Boards category; Hi I was working on my project file and I have to do work with structs. So I created a ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    53

    Random behaviour structs please explain

    Hi I was working on my project file and I have to do work with structs. So I created a sample program that is small to see how to implement in my program.

    Below is the program:


    Code:
    #include <stdio.h>
    
    typedef struct{
    	double x;
    	double y;
    }data;
    
    data function(void);
    
    int main(void)
    {
    	double a, b;
    	data table;
    	
    	table = function();
    		
    	printf("%lf   %lf", table.x, table.y);
    
    	return 0;
    }
    
    data function(void)
    {
    	data fTable;
    	
    	fTable.x = 4;
    	fTable.y = 5;
    	
    	return fTable;
    }

    Can I make a struct = another struct if they are of the same type?
    the output is 3 doubles (3.90000000 3.444000 3.09000), even if I take the printf out of the program lol!

    Help please!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    1. Of course.
    2. This is false. The output of the program you have written and posted here is "4.000000 5.000000". Are you sure you actually compiled the program and are running this program and not some other one?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a random array of integers
    By Vidak in forum C# Programming
    Replies: 2
    Last Post: 11-09-2007, 05:00 AM
  2. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  3. Replies: 1
    Last Post: 12-14-2002, 12:51 AM
  4. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 07:10 AM
  5. Random Problem?
    By dizz in forum C++ Programming
    Replies: 4
    Last Post: 11-20-2002, 04:00 PM

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