login about faq

Due to the large amount of spam accounts, we temporarily disabled new user sign ups. To override this, email newuser.lgqa@gmail.com and an admin will determine if you are permitted to join


This is a C app for finding numbers from base 10 to bases 2-16. Here is the code:

\#include "stdio.h" //With the code font, it wouldn't show stdio.h if I put it in less or greater than signs

int main(void)

{

const char baseDigits[16] ={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

int convertedNumber[64];

long int numberToConvert;

int nextDigit, base, index = 0;

_Bool keep_going = 1;

//get number and base

while(keep_going)
    {
                     printf("Number to be converted?\n");
                     scanf("%ld", &numberToConvert);

printf("base to convert to (2-16)?\n");
                     scanf("%i", &base);

do {
                         convertedNumber[index] = numberToConvert % base;
                         index++;
                         numberToConvert = numberToConvert / base;
                     }

while(numberToConvert != 0);

for(--index; index >= 0; --index){
                                  nextDigit = convertedNumber[index];
                                  printf("%c", baseDigits[nextDigit]);

}
    return 0;
    }

When I try to compile it, Dev-C++ says that the last line of code, the closing brace for main, is an error. The exact wording is "In function main: Syntax error at end of input". Any suggestions? And no hate speech about C or Dev-C++, either.

asked Oct 16 '10 at 12:49

HHBones's gravatar image

HHBones
4.1k6182118

edited Jan 17 '11 at 20:26


Problem is trvial make sure your { } are always aligned you missed one.

//Revision to HHBones question "Spot the error in my code"
//Problem missing '}'
#include <stdio.h>

int main(void)

{
    const char baseDigits[16] ={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    int convertedNumber[64];

    long int numberToConvert;

    int nextDigit, base, index = 0;

    _Bool keep_going = 1;

    //get number and base

    while(keep_going)
    {
        printf("Number to be converted?\n");
        scanf("%ld", &numberToConvert);

        printf("base to convert to (2-16)?\n");
        scanf("%i", &base);

        do {
             convertedNumber[index] = numberToConvert % base;
             index++;
             numberToConvert = numberToConvert / base;
           }
        while(numberToConvert != 0);

        for(--index; index >= 0; --index)
        {
                      nextDigit = convertedNumber[index];
                      printf("%c", baseDigits[nextDigit]);

        }
    }
     return 0;
}

answered Jan 17 '11 at 15:12

trueb's gravatar image

trueb
15.4k53104260

I never was good about braces...

(Jan 17 '11 at 20:33) HHBones HHBones's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported


Join Us in the Chat Room

Tags:

×130
×97
×38
×8
×5
×2

Asked: Oct 16 '10 at 12:49

Seen: 1,548 times

Last updated: Jun 20 '11 at 08:09