problem with complex numbers

This is a discussion on problem with complex numbers within the C Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    dsc
    dsc is offline
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    scanf("%lf", &z->x);
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    dsc
    dsc is offline
    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, 04: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, 09:43 AM
  4. Complex Numbers with Visual C++
    By thetinman in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2007, 03:42 PM
  5. Random numbers problem
    By ManiacBR in forum C++ Programming
    Replies: 4
    Last Post: 11-09-2006, 12:34 PM

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