Thread: problem with complex numbers

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    4

    problem with complex numbers

    hi,
    i wrotte a code but doesn't work..since i'm beginner i can't find where is my error..when i compile my code i get no error..but when i run it i get: Segmentation fault

    thx in advance for ur help

    code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    struct Complex_s{
     double x;
     double y;
    };
    
    void readComplex(struct Complex_s *z); // 1 
    void printComplex(struct Complex_s *z); // 2
    
    int main(int argc, char *argv[])
    {
    struct Complex_s z1;
    
    printf("Number: \n");
    
    readComplex(&z1);
    printComplex(&z1);
    
    return 0;
    }
    
    void readComplex(struct Complex_s *z) 
    {
    printf("R-Part: \n");
    scanf("%lf", z->x);
    printf("I-part: \n");
    scanf("%lf", z->y);
    }
    
    void printComplex(struct Complex_s *z)
    {
    printf("%lf, %lfi\n", z->x, z->y);
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    scanf("%lf", &z->x);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    4
    Quote Originally Posted by vart
    scanf("%lf", &z->x);
    thx vart..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Complex Numbers
    By Link_26 in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2009, 03:20 AM
  2. Problem with adding up numbers from a txt file
    By Leo12 in forum C Programming
    Replies: 1
    Last Post: 02-18-2009, 01:50 PM
  3. complex numbers
    By Mastiff in forum C Programming
    Replies: 6
    Last Post: 09-12-2008, 08:43 AM
  4. Complex Numbers with Visual C++
    By thetinman in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2007, 02:42 PM
  5. Random numbers problem
    By ManiacBR in forum C++ Programming
    Replies: 4
    Last Post: 11-09-2006, 12:34 PM