Thread: Does'nt excute program always crashes

  1. #1
    Registered User
    Join Date
    Sep 2005

    Does'nt excute program always crashes

    I wrote this code to convert a mathematical equation from 1 form to another but when you put in everything it just crashes. I was hoping if some can point out my mistakes to me.

    #include <stdio.h>
    #include <math.h>
    int main()
    	char z,w,G,num,den;
    	float Ts;
    printf("Please enter the samplling rate: ");
    printf("Please enter the numarator in terms of w: ");
    printf("Please enter the denominator in terms of w: ");
    printf("The discrete transfer function in the form of Z is %s \n",G);
    return 0;

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    You are asking for a string here:

    Yet you are trying to put it into a single char variable. That will not work. You should either store your string (which is what scanf is looking for with %s) in an array, or else change your call to scanf to be looking for a single char (%c) If you do go the first way, then you ought to limit the amount of input to you scanf call with a width specifier, so the user does not overflow the array.

  3. #3
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Sydney, Australia

    You already posted almost identical code to another thread, which already contains feedback. The only things you've done different this time is add #include <math.h>, which doesn't make any difference, because you're not using anything from math.h, and you changed the format string from %c to %s, which makes even less sense. If you want to read in the numbers as strings first and convert them, then read them into a char array, not a single character.

    Pay attention to the feedback on the previous thread, and if you have other questions, post them on that thread.

    This thread should probably be locked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple login program - Crashes :(
    By spadez in forum C Programming
    Replies: 1
    Last Post: 03-23-2009, 04:16 PM
  2. Replies: 3
    Last Post: 02-29-2008, 01:29 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. program crashes on closure.
    By ssjnamek in forum C++ Programming
    Replies: 7
    Last Post: 09-26-2005, 04:55 PM
  5. My program crashes with this code
    By blackwyvern in forum C++ Programming
    Replies: 3
    Last Post: 01-28-2002, 12:28 AM