Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7592447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:54:31+00:00 2026-05-30T20:54:31+00:00

I had written C++ code for a problem. After that i have tried to

  • 0

I had written C++ code for a problem. After that i have tried to write a C code that can solve the same problem.
The header file Bit.h is:

#ifndef Bit_included
#define Bit_included

struct Bit
{
    int width;
    int value;
};
void init();
void initvalues(int v, int w);
void initcopy(const Bit& b);
int getWidth();
int getValue();
Bit & plus(int newval);
#endif //Bit_included

The file Bit.c is:

#include "Bit.h"
#include "math.h"
using namespace std;
void init()
{
    value=0;
    width=0;
}
void initvalues(int v,int w)
{
    value=v;
    width=w;
}
void initcopy(const Bit& b)
{
    value=b.value;
    width=b.width;
}
int getWidth()
{
    return width;
}
int getValue()
{
    return value;
}
Bit & plus(int newval)
{
    value+=newval;
    if(value>=pow(2,width))
     cout<<"Overflow";
    return *this;
}

Error in the header files are:

Line 11: error: expected ';', ',' or ')' before '&' token
Line 14: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token

Error in Bit.c are:

Line 3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
In function 'init':
Line 6: error: 'value' undeclared (first use in this function)
Line 6: error: (Each undeclared identifier is reported only once
Line 6: error: for each function it appears in.)
Line 7: error: 'width' undeclared (first use in this function)
In function 'initvalues':
Line 11: error: 'value' undeclared (first use in this function)
Line 12: error: 'width' undeclared (first use in this function)
t.c: At top level:
Line 14: error: expected ';', ',' or ')' before '&' token
In function 'getWidth':
Line 21: error: 'width' undeclared (first use in this function)
In function 'getValue':
Line 25: error: 'value' undeclared (first use in this function)
t.c: At top level:
Line 27: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token

How can i write the correct code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:54:32+00:00Added an answer on May 30, 2026 at 8:54 pm

    C and C++ are two rather different languages. Your code is neither valid C nor valid C++. It is, however, using quite a few constructs and features that are specific to C++ and are not available in C.

    If you wish to learn C, my advice would be to pick up a good textbook. It’ll be much more efficient than just guessing your way.

    Here is a good starting point: The Definitive C Book Guide and List

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Written a webservice with VS2008 after I had Added Reference to that
I'm having a problem with some code I've written. I've had to anonymize it,
I have written some code that makes use of an open source library to
I had written this code out using Adobe CS3 and have recently upgraded to
I recently inherited some code that someone else had written. I discovered that everywhere
I was glancing through some code I had written in my Perl class and
As I had written in title, I have SQL query, run on Oracle DB,
I am trying to write a program in PHP which I had already written
I had the following idea: Say we have a webapp written using django which
I used FxCop to analyze some code I had written. I had exposed a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.