Click here to Skip to main content
15,072,311 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Does anyone know a C++-to-C-converter? I cant find the converter, but I need it to convert C++-coding to C.


Comment from Smithers-Jones: I deleted you new question and put the content below into this question, since they are obviously related.


#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main()
{
int numberM = 0;
cout << endl << "Enter m: ";
cin >> numberM;

int numberN = 0;
cout << endl << "Enter n: ";
cin >> numberN;

for (int i = (numberM + 1); i < numberN; i++)
{
cout << endl << i;
}

cout << endl;
system("PAUSE");
return 0;
}


may i know the above coding is it showing a program to accept 2 numbers m and n and to display all numbers between m and n? may i know how to change the c++ code to make it into c?

What I have tried:

Changed the question title to prevent abuse
Posted
Updated 6-Dec-20 19:46pm
v4
Comments
Albert Holguin 3-Apr-11 15:31pm
   
why would you want to convert C++ to C?
Jayfam 3-Apr-11 15:33pm
   
i found a c++ coding which i needed, but i want it in c because i learn c and do no learn c++ before
Albert Holguin 3-Apr-11 15:35pm
   
even though there may be a converter, i've never seen one, you can always post the chunks of code that you don't understand in CodeProject Q&A and ask for clarification.
Jayfam 3-Apr-11 15:36pm
   
ok, thx
Smithers-Jones 3-Apr-11 15:44pm
   
I deleted your new question and put the content below into this question, since they are obviously related. You can always improve your question instead of starting a new one.
Jayfam 3-Apr-11 15:45pm
   
ok, thanx

Why? That is not going to be too useful, if it is true C++.

The basic syntax of C++ is C. So it is possible to write a C program in C++. Indeed, some "professionals" have never done anything else.

However, C++ is a major superset of C, containing a huge amount of stuff that just isn't there in the base language. Classes for example. Polymorphism. Just about everything which makes C++ usable as a modern language.

While they do exist, (the early C++ compilers were just that, and a quick Google will find you something that will do the job) C++ to C conversion would be a very retrograde step, and will not produce anything you would want to maintain, or indeed look at for too long.

Is there a specific reason you want to do it? Because if there isn't, I would strongly recommend you stick to C++.
   
Comments
Jayfam 3-Apr-11 15:50pm
   
but im learning C programming now
OriginalGriff 3-Apr-11 15:58pm
   
So if you are learning C now, why do you want to translate C++? It won't produce good C because it will translate structures and concepts into a more limited environment!
Jayfam 3-Apr-11 16:00pm
   
oic, i understand what u mean. thanks
   
Good Answer. My 5.
--SA
Here's what the code should look like (no error checking, which you should add):
int main()
{
 int numberM =0, numberN=0, i=0;

 printf("Enter m: ");
 scanf("%d", &numberM);
 printf("Enter n: ");
 scanf("%d", &numberN);

 for(i = (numberM +1); i<numberN; i++)
	printf("%d\n", i);

 return 0;
}


Things you should know that were replaced and why:
1) All std namespace objects and functions are C++, they were replaced with appropriate printf/scanf calls.
2) In C, all variable declarations must occur at the beginning of the function, not the case with C++.

What's lacking in this code:
1) Checking for errors
2) scanf is NOT type safe, meaning the result of a user putting in the wrong input type is undefined
   
v2
Comments
CPallini 20-Mar-17 5:52am
   
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900