Need Help with A C Program

    • Re: Need Help with A C Program

      Hi. I know C, and I'm somewhat experienced.

      First, do you know how to convert decimal values to binary without the aid of a computer? For example, some simple conversions:

      8 = 1000
      1 = 0001
      36 = 100100

      Now, to do this in C is something different. It's pretty lame because it's a complicated process. I think you can use snprintf(); for it, but I'm not sure. I'd write a program myself, but I don't know how to flip the binary value. I found this example though:

      (I guess I can't post links yet)

      That example is pretty huge and extensive. I found this example function in the comments on that page:

      long bin2dec(char *s)
      {
      long r=0;
      for ;) *s; r = ( r [insert two left-pointing carets here] 1 ) | ( *s++ - '0' ) );
      return r;
      }

      I know nothing about bitwise operators, but I do know how to use functions. You can create your conversion program based on the snippet that I just quoted. If you need any more help, just post here.
    • Re: Need Help with A C Program

      Wow that coding is something, im that all that experienced as yet, but i'm good at C so far, i have gotten solutions to it so far, the only thing i was thing is umm suppose someone enters a long binary number, i wudnt really know how long the person was thinking on entering, so i think im gonna alert the user to enter a sentinel value, thereby having them being able to enter as much long binary, but im still focusing on the loop, cuz then longer numbers means more calculations. Hmmmm........ im thinking right now, lol...i'll try figuring this out by tonight.... Hey we should get all Programmers to get into this forum, i barely see any of that, by the way how much time u got learning C, i got bout 2 months thats all, and im soooooooo enjoying the language... Thanks!!!
    • Re: Need Help with A C Program

      Matus wrote:

      Wow that coding is something, im that all that experienced as yet, but i'm good at C so far, i have gotten solutions to it so far, the only thing i was thing is umm suppose someone enters a long binary number, i wudnt really know how long the person was thinking on entering, so i think im gonna alert the user to enter a sentinel value, thereby having them being able to enter as much long binary, but im still focusing on the loop, cuz then longer numbers means more calculations.


      The char variable is what's sent to the function. IE, you can get the number from the user with gets() or something, and directly pass it to the function I posted. I dunno if number length would be an issue in the function.

      As for your loop:

      char userinput[100];

      int main()
      {
      gets(userinput);
      printf("%s = %in",userinput,bin2dec(userinput);
      }

      That %i may have to be %d, and userinput may have to be *userinput.

      Matus wrote:


      Hey we should get all Programmers to get into this forum, i barely see any of that, by the way how much time u got learning C, i got bout 2 months thats all, and im soooooooo enjoying the language... Thanks!!!


      I've known C for about two years(Learned when I was 15). I'm book taught, not school taught(and it shows).

      It's cool that you like the language already. Wait until you get a bit deeper into it and you start messing with libraries. Things like SDL and Irrlicht make you glad you learned C.

      As for getting a group together here, I dunno if it's my place to do so. I'm super new here.
      [SIZE=1]
      [/SIZE]
    • Re: Need Help with A C Program

      Cool, thanks man for the help, i got the program working, and submitted it. Thanks for the help, well as for members here i too am pretty new, so well jst plan on continuing i guess, or hey do u know any other like really good forum for programming?? Let me know, as for help i guess ill have to keep posting so i get help , lol, thanks again!!
    • Re: Need Help with A C Program

      Matus wrote:

      Cool, thanks man for the help, i got the program working, and submitted it. Thanks for the help, well as for members here i too am pretty new, so well jst plan on continuing i guess, or hey do u know any other like really good forum for programming?? Let me know, as for help i guess ill have to keep posting so i get help , lol, thanks again!!


      No problem. It's not often that I run into someone who I can help with C.

      I know a couple of good places if you own an iPod, but otherwise, not really.

      Good luck with C. Sometimes it's a pain, sometimes it owns.
      [SIZE=1]
      [/SIZE]