Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,397 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,236 people online right now. Registration is fast and FREE... Join Now!




Converting from C++ to C

 
Reply to this topicStart new topic

Converting from C++ to C

mchay
3 Feb, 2008 - 12:19 PM
Post #1

New D.I.C Head
*

Joined: 30 Jan, 2008
Posts: 12

I've made a box in C++ code, that I want to use in a little C application I'm planning. How can I convert it to function? My Turbo C++ compiler doesnt seem to have the iostream.h. What is the best way to tackle my problem?

CODE

#include <iostream.h>
#include <conio.h>

void ramme(int a, int b, int c, int d)

{
    int resetA = a, resetB = b;

    /* sides */
    textcolor(YELLOW);
        textbackground(BLUE);
    while (a<c)
    {
        gotoxy(a,b);
        cprintf("%c", 205);
        gotoxy(a,d);
        cprintf("%c", 205);
        a++;
    }
    a = resetA;

    while (b<d)
    {
        gotoxy(a,b);
        cprintf("%c", 186);
        gotoxy(c,b);
        cprintf("%c", 186);
        b++;
    }
    b = resetB;

    /* corners */
    gotoxy(c,b);
    cprintf("%c", 187);
    gotoxy(a,b);
    cprintf("%c", 201);
    gotoxy(c,d);
    cprintf("%c", 188);
    gotoxy(a,d);
    cprintf("%c", 200);

}

int main()

{

ramme(30,10,50,20);
return 0;

}


User is offlineProfile CardPM
+Quote Post

Bench
RE: Converting From C++ To C
3 Feb, 2008 - 12:31 PM
Post #2

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 683



Thanked: 24 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
You haven't actually used any C++ in your program at all. Whatever library you've used for cprintf, gotoxy, textcolor, etc, will probably all work on your C compiler too, assuming they're both by the same vendor (none of it is standard)
User is offlineProfile CardPM
+Quote Post

mchay
RE: Converting From C++ To C
3 Feb, 2008 - 12:38 PM
Post #3

New D.I.C Head
*

Joined: 30 Jan, 2008
Posts: 12

I am getting Declaration syntax errors (IOSTREAM.H) that I'm not getting if I compile it as .CPP.
User is offlineProfile CardPM
+Quote Post

GWatt
RE: Converting From C++ To C
3 Feb, 2008 - 12:45 PM
Post #4

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,356



Thanked: 31 times
Dream Kudos: 500
My Contributions
Well, you can use <stdio.h>. Also, anything that works in c will also work in c++, objective c, or objective c++. So, i would just leave it using whatever c++ code you are using, and call the c functions as needed.
User is offlineProfile CardPM
+Quote Post

Bench
RE: Converting From C++ To C
3 Feb, 2008 - 12:51 PM
Post #5

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 683



Thanked: 24 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
QUOTE(mchay @ 3 Feb, 2008 - 08:38 PM) *

I am getting Declaration syntax errors (IOSTREAM.H) that I'm not getting if I compile it as .CPP.

Then remove that header. You haven't actually used anything from iostream in your program anyway.

In C++ it should be called <iostream> without the .h extension, though if you're running a very old compiler, it may not support standard C++. C has no header under the name <iostream> or <iostream.h>
User is offlineProfile CardPM
+Quote Post

mchay
RE: Converting From C++ To C
3 Feb, 2008 - 01:08 PM
Post #6

New D.I.C Head
*

Joined: 30 Jan, 2008
Posts: 12

D'oh. That worked great. As you probably can hear I'm pretty new to programming :-). Thanks for the help.
User is offlineProfile CardPM
+Quote Post

Cyborg Ninja
RE: Converting From C++ To C
5 Feb, 2008 - 09:16 AM
Post #7

D.I.C Head
**

Joined: 29 Jan, 2008
Posts: 56

In high school (only a few years ago) we used a REALLY old compiler. My God. I couldn't even tell you the name. We had to use <iostream.h> instead of the standard, too. I don't know we didn't just use Visual C++. I guess our teacher didn't know how to use it. She taught Java when she admitted that she didn't even know how to program in it.
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Converting From C++ To C
5 Feb, 2008 - 10:11 AM
Post #8

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,113



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(Cyborg Ninja @ 5 Feb, 2008 - 10:16 AM) *

In high school (only a few years ago) we used a REALLY old compiler. My God. I couldn't even tell you the name. We had to use <iostream.h> instead of the standard, too. I don't know we didn't just use Visual C++. I guess our teacher didn't know how to use it. She taught Java when she admitted that she didn't even know how to program in it.

At least your school had programming classes. In my highschool we had typing class on Apple II's & Commodores.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:12AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month