Problem with beginner code... please help

This is a discussion on Problem with beginner code... please help within the C Programming forums, part of the General Programming Boards category; Ok so I'm making this program and its pretty much just converting from one base number to another (i.e. base ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    12

    Problem with beginner code... please help

    Ok so I'm making this program and its pretty much just converting from one base number to another (i.e. base 16 to base 10[normal]). Anyhow, that's not really important, what is is that my program is crashing.... now the weird thing is it works fine with certain input. As long as the third variable is a LETTER it works fine. The letter represents a number in some bases and the program runs and works fine (as far as i got it) with this input. but if i put in a number the program completely crashes. even when i put in a test printf at the very beginning of the code it doesn't get read..... idk wtf would cause that... i've never had a problem like this (i've only had a year programming experience in java.. very new to C). If anyone could help i got them on reps for life.

    Code:
    #include <math.h> #include <s - Anonymous - tGcu2Zeg - Pastebin.com

    what works....
    input 16 10 EE
    output so far: 238 (converted into base 10..haven't got any farther yet since i'm trying to debug this).

    what doesn't work....
    input 16 10 1 (or any number for last input)
    program acts like its continuously looping and i've tried putting print statements everywhere but nothing gets printed...don't know whats wrong

  2. #2
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198

    Smile

    Quote Originally Posted by rkrajnov View Post
    Ok so I'm making this program and its pretty much just converting from one base number to another (i.e. base 16 to base 10[normal]). Anyhow, that's not really important, what is is that my program is crashing.... now the weird thing is it works fine with certain input. As long as the third variable is a LETTER it works fine. The letter represents a number in some bases and the program runs and works fine (as far as i got it) with this input. but if i put in a number the program completely crashes. even when i put in a test printf at the very beginning of the code it doesn't get read..... idk wtf would cause that... i've never had a problem like this (i've only had a year programming experience in java.. very new to C). If anyone could help i got them on reps for life.

    Code:
    #include <math.h> #include <s - Anonymous - tGcu2Zeg - Pastebin.com

    what works....
    input 16 10 EE
    output so far: 238 (converted into base 10..haven't got any farther yet since i'm trying to debug this).

    what doesn't work....
    input 16 10 1 (or any number for last input)
    program acts like its continuously looping and i've tried putting print statements everywhere but nothing gets printed...don't know whats wrong
    Hello and welcome to the board.

    To get the max help, you should post your code using code tags. I may not be able
    to help you with your problem but others here can.

    I still use the link that I'm giving you now from time to time... it helps newcomers
    how to ask the right question. :-)

    How To Ask Questions The Smart Way

  3. #3
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    977
    First things first: you've forgotten to include the headers stdlib.h, string.h, and ctype.h. If you're using gcc, always build with the -Wall flag. This enables a lot of very useful warnings (and one or two stupid ones). If you're using another compiler, consult its documentation on how to turn up the warning level.

    Your crash is indeed the result of an infinite loop, here:
    Code:
    while(numberstore > 0){
      digit[counter] = numberstore % 10;
      numberstore / 10;
      counter++;
    }
    You meant to say “numberstore /= 10”, not “numberstore / 10”.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. problem with parser code
    By ssharish2005 in forum C Programming
    Replies: 2
    Last Post: 12-02-2005, 06:38 AM
  3. code problem
    By maritos in forum C Programming
    Replies: 1
    Last Post: 11-27-2005, 04:22 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. problem with my code
    By stilllearning in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2003, 03:02 PM

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