phunguz February 2016

Having trouble finding what is causing this error

I am trying to create a program that will output the binary code for 16 numbers. Here is what i have so far:

#include <stdio.h>
#include <stdlib.h>
int i;
int count;
int mask;

int i = 0xF5A2;
int mask = 0x8000;
int main()
{
printf("Hex Value= %x Binary= \n", i);
{
    for (count=0; count<15; count++1)
    {
        if (i&mask)
            printf("1\n");
        else
            printf("0\n");
    }
    (mask = mask>>1);
}
return 0;
}

The error:

|16|error: expected ')' before numeric constant|

Also let me know if I have any other mistakes, Thanks in advance!

Answers


abelenky February 2016

The error is referring to this expression:

count++1

Which makes no sense.

I assume you want:

count++ 

Making the line

for (count=0; count<15; count++)

You have other strangeness in your code such as:

int i;              // Declare an integer named "i"
int mask;           // Declare an integer named "mask"

int i = 0xF5A2;     // Declare another integer also named "i".  Did you forget about the first one???
int mask = 0x8000;  // Did you forget you already declared an integer named "mask"?

printf("Hex Value= %x Binary= \n", i);
{
    [...]
}  // Why did you put a bracket-scope under a PRINTF call?
   // Scopes typically follow loops and if-statements!

 (mask = mask>>1);  // Why put parens around a plain-old expression??


After fixing weirdness in your code, it should look like:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i = 0xF5A2;
    int mask = 0x8000;

    printf("Hex Value= %x Binary= \n", i);
    for (int count=0; count<15; ++count, mask>>=1)
    {
        printf("%d\n", (i&mask)? 1 : 0);
    }
    return 0;
}

Post Status

Asked in February 2016
Viewed 1,871 times
Voted 8
Answered 1 times

Search




Leave an answer