Thread: testing struct

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    16

    testing struct

    I have error in the line 'x=....' & 'printf(....' , during compile,
    what wrong I have write in the program?

    thk a lot

    Code:
    #include <stdio.h>
    #include <math.h>
    
    struct measure {
    
      int feet;
      int inch;
    };
    
    struct measure tofeetinch(float inch) {
      struct measure temp;
    
      temp.feet=inch /12;
      temp.inch=fmod (inch, 12);
    
      return temp;
    }
    
    void main(){
    
      int temp, x, feet=90, inch=200;
      struct measure tofeetinch;
    
      x=tofeetinch(inch);
      printf("x, %d", temp.inch);
    
      fflush(stdin);
      getchar();
    
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    http://cboard.cprogramming.com/showt...threadid=50530
    You persist with void main and fflush(stdin)

    > struct measure tofeetinch;
    It's also the name of your function
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    8

    Re: testing struct

    Originally posted by zp523444
    Code:
    void main(){
    
      int temp, x, feet=90, inch=200;
      struct measure tofeetinch;
      x=tofeetinch(inch);
      printf("x, %d", temp.inch);
      fflush(stdin);
      getchar();
    
    
    }
    [/B]
    x is of type 'int' whereas the function tofeetinch() returns a variable of type struct measure. You can't assign different types like this. (Some types, yes. These types, no). And "%d" only prints type int. It will not print a struct type.

    TBH, the rest of your program doesn't make sense to me. You can simplify it a lot, but whatever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  2. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM