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

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




converting c# to c

 
Reply to this topicStart new topic

converting c# to c

ihcs50
2 Jan, 2008 - 08:38 PM
Post #1

New D.I.C Head
*

Joined: 2 Jan, 2008
Posts: 8

Is there an online tool to convert C# to C?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Converting C# To C
2 Jan, 2008 - 11:01 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You can't convert down from C# to C because C# is built on the idea of the .NET framework and classes, two things not known to C. Even if you could it would blow up to like a 1000 times the lines and would be a huge mess.

Well.. I take that back if it is something super simple like declaring a variable you can obviously have a shot. But anything beyond a simple function would be impossible.

This post has been edited by Martyr2: 2 Jan, 2008 - 11:02 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Converting C# To C
3 Jan, 2008 - 05:19 AM
Post #3

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
To add to Martyr's post, there are many things you could recreate in C form C#, but there are many more than could not be recreated (especially with regards to some of the more complex classes and services). there is no online tool for C# to C conversion (or any tool at all, to my knowledge), but if you would care to post the C# code you wish to convert, one of us that is skilled in both languages can provide a more accurate assessment as to whether that piece of code can be converted.
User is offlineProfile CardPM
+Quote Post

ihcs50
RE: Converting C# To C
3 Jan, 2008 - 08:09 PM
Post #4

New D.I.C Head
*

Joined: 2 Jan, 2008
Posts: 8

it's a long one! it is suppossed to make shuffle, and deal a deck of cards.
CODE

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace CardDraw2Jokers
{
        /// <summary>
        /// Summary description for Form1.
        /// </summary>
        public class uiCardGameForm : System.Windows.Forms.Form
        {
                private System.Windows.Forms.Button uiDealButton;
                private System.Windows.Forms.PictureBox uiCard0PictureBox;
                private System.Windows.Forms.PictureBox uiCard1PictureBox;
                private System.Windows.Forms.PictureBox uICard2PictureBox;
                private System.Windows.Forms.PictureBox uiCard3PictureBox;
                private System.Windows.Forms.Button uiInfoButton;
                /// <summary>
                /// Required designer variable.
                /// </summary>
                private System.ComponentModel.Container components = null;

                public uiCardGameForm()
                {
                        //
                        // Required for Windows Form Designer support
                        //
                        InitializeComponent();

                        //
                        // TODO: Add any constructor code after InitializeComponent call
                        //
                }

                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                protected override void Dispose( bool disposing )
                {
                        if( disposing )
                        {
                                if (components != null)
                                {
                                        components.Dispose();
                                }
                        }
                        base.Dispose( disposing );
                }

                #region Windows Form Designer generated code
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeComponent()
                {
                        System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(uiCardGameForm));
                        this.uiCard0PictureBox = new System.Windows.Forms.PictureBox();
                        this.uiCard1PictureBox = new System.Windows.Forms.PictureBox();
                        this.uICard2PictureBox = new System.Windows.Forms.PictureBox();
                        this.uiCard3PictureBox = new System.Windows.Forms.PictureBox();
                        this.uiDealButton = new System.Windows.Forms.Button();
                        this.uiInfoButton = new System.Windows.Forms.Button();
                        this.SuspendLayout();
                        //
                        // uiCard0PictureBox
                        //
                        this.uiCard0PictureBox.Image = ((System.Drawing.Image)
(resources.GetObject("uiCard0PictureBox.Image")));
                        this.uiCard0PictureBox.Location = new System.Drawing.Point(24, 24);
                        this.uiCard0PictureBox.Name = "uiCard0PictureBox";
                        this.uiCard0PictureBox.Size = new System.Drawing.Size(72, 96);
                        this.uiCard0PictureBox.TabIndex = 0;
                        this.uiCard0PictureBox.TabStop = false;
                        //
                        // uiCard1PictureBox
                        //
                        this.uiCard1PictureBox.Image = ((System.Drawing.Image)
(resources.GetObject("uiCard1PictureBox.Image")));
                        this.uiCard1PictureBox.Location = new System.Drawing.Point(128,
24);
                        this.uiCard1PictureBox.Name = "uiCard1PictureBox";
                        this.uiCard1PictureBox.Size = new System.Drawing.Size(72, 96);
                        this.uiCard1PictureBox.TabIndex = 1;
                        this.uiCard1PictureBox.TabStop = false;
                        //
                        // uICard2PictureBox
                        //
                        this.uICard2PictureBox.Image = ((System.Drawing.Image)
(resources.GetObject("uICard2PictureBox.Image")));
                        this.uICard2PictureBox.Location = new System.Drawing.Point(232,
24);
                        this.uICard2PictureBox.Name = "uICard2PictureBox";
                        this.uICard2PictureBox.Size = new System.Drawing.Size(72, 96);
                        this.uICard2PictureBox.TabIndex = 2;
                        this.uICard2PictureBox.TabStop = false;
                        //
                        // uiCard3PictureBox
                        //
                        this.uiCard3PictureBox.Image = ((System.Drawing.Image)
(resources.GetObject("uiCard3PictureBox.Image")));
                        this.uiCard3PictureBox.Location = new System.Drawing.Point(336,
24);
                        this.uiCard3PictureBox.Name = "uiCard3PictureBox";
                        this.uiCard3PictureBox.Size = new System.Drawing.Size(72, 96);
                        this.uiCard3PictureBox.TabIndex = 3;
                        this.uiCard3PictureBox.TabStop = false;
                        //
                        // uiDealButton
                        //
                        this.uiDealButton.BackColor =
System.Drawing.SystemColors.ActiveBorder;
                        this.uiDealButton.Font = new System.Drawing.Font("Microsoft Sans
Serif", 10.2F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                        this.uiDealButton.Location = new System.Drawing.Point(52, 136);
                        this.uiDealButton.Name = "uiDealButton";
                        this.uiDealButton.Size = new System.Drawing.Size(136, 32);
                        this.uiDealButton.TabIndex = 4;
                        this.uiDealButton.Text = "Deal Cards!!";
                        this.uiDealButton.Click += new
System.EventHandler(this.uiDealButton_Click);
                        //
                        // uiInfoButton
                        //
                        this.uiInfoButton.BackColor =
System.Drawing.SystemColors.ActiveBorder;
                        this.uiInfoButton.Font = new System.Drawing.Font("Microsoft Sans
Serif", 10.2F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                        this.uiInfoButton.Location = new System.Drawing.Point(244, 136);
                        this.uiInfoButton.Name = "uiInfoButton";
                        this.uiInfoButton.Size = new System.Drawing.Size(136, 32);
                        this.uiInfoButton.TabIndex = 5;
                        this.uiInfoButton.Text = "More Info";
                        this.uiInfoButton.Click += new
System.EventHandler(this.uiInfoButton_Click);
                        //
                        // uiCardGameForm
                        //
                        this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
                        this.BackColor = System.Drawing.Color.Green;
                        this.ClientSize = new System.Drawing.Size(432, 224);
                        this.Controls.Add(this.uiInfoButton);
                        this.Controls.Add(this.uiDealButton);
                        this.Controls.Add(this.uiCard3PictureBox);
                        this.Controls.Add(this.uICard2PictureBox);
                        this.Controls.Add(this.uiCard1PictureBox);
                        this.Controls.Add(this.uiCard0PictureBox);
                        this.Name = "uiCardGameForm";
                        this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
                        this.Text = "Card Game Tite";
                        this.ResumeLayout(false);

                }
                #endregion

                /// <summary>
                /// The main entry point for the application.
                /// </summary>
                [STAThread]
                static void Main()
                {
                        Application.Run(new uiCardGameForm());
                }

                /* I wrote everything below here.  Everything above
was created by the Windows Form Designer.*/

                #region VARS
                //cstintEND will determine the number of cards, which is 54, and
could be 13, 15, 26, 28, and so on depending on how many suits/jokers
you are using.
                public const int cstintEND = 54;
                //intCardArray holds the cards
                int[] intCardArray = new int[54];
                //this starts the random generator.
                Random generateRandom = new Random();
                #endregion

                /*the cards and buttons are already laid out, set with
the back of a card as the default image.  When the button is clicked,
it then shuffles the cards, deals the top four, and stops.  It re-
shuffles and deals them when the button is clicked again.*/

                private void uiDealButton_Click(object sender, System.EventArgs e)
                {
                        int i;
                        //shuffle cards
                        for ( i = 0; i <= 53; i++)
                        {
                                intCardArray[i] = generateRandom.Next(1, cstintEND);
                        }

                        /* Since intCardArray[0] is the first to be
assigned, it doesn't have to be checked for duplicity, but the others
have to be checked with all that came before them, and the conditions
for these loops get very big when you actually deal ten or twelve
cards out.*/

                        //be sure there are no duplicates.
                        while (intCardArray[1] == intCardArray[0])
                                intCardArray[1] = generateRandom.Next(1, cstintEND);

                        while ((intCardArray[2] == intCardArray[1]) || (intCardArray[0] ==
intCardArray[2]))
                                intCardArray[2] = generateRandom.Next(1, cstintEND);

                        while ((intCardArray[3] == intCardArray[2]) || (intCardArray[3] ==
intCardArray[1]) || (intCardArray[3] == intCardArray[0]))
                                intCardArray[3]= generateRandom.Next(1, cstintEND);
                        //
                        //deal the cards
                        //
                        i = 0; //reset i, recycling a variable
                        /*As you can see, the overloading of the array makes card
placement much easier than with if statements or switches. */

                        //cards must be named and placed in the project's bin/debug folder
to work this way.
                        this.uiCard0PictureBox.Image = Image.FromFile(intCardArray[i] +
".png");
                        this.uiCard1PictureBox.Image = Image.FromFile(intCardArray[i + 1] +
".png");
                        this.uICard2PictureBox.Image = Image.FromFile(intCardArray[i + 2] +
".png");
                        this.uiCard3PictureBox.Image = Image.FromFile(intCardArray[i + 3] +
".png");

                        /* A note on the above: It may be possible,
when assigning large numbers of cards, to loop through the process by
making a variable ==  X in this.uiCardXPictureBox.  I'm not sure right
off hand how it would be done, but it could be looked into.*/
                }

                private void uiInfoButton_Click(object sender, System.EventArgs e)
                {
                        MessageBox.Show("This program is written to shuffle a deck of cards
and deal the top four.  It automatically re-shuffles the deck each
time the deal button is pressed, dealing four re-randomized cards.
The images are named by number and saved in the bin/debug folder of
the project, simplifying the image assignment process.",
"Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
        }
}

/* And there you have it.  Just open up your copy of Visual Studio
(with Visual C#.NET installed, of course), copy and paste this code
into it, save it, and press F5 to run it and see how it actually
works.  Happy coding!  */

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Converting C# To C
3 Jan, 2008 - 08:25 PM
Post #5

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Yeah see much of this program is dealing with concepts not even conceived of back in the days of C. C wasn't even a real solid GUI language and so how would you do something like a picturebox? Not to mention this uses a lot of images and classes. C doesn't have classes. That is why C++ was created.

This program cannot be directly converted to C without a massive rewrite. sad.gif
User is offlineProfile CardPM
+Quote Post

ihcs50
RE: Converting C# To C
3 Jan, 2008 - 10:21 PM
Post #6

New D.I.C Head
*

Joined: 2 Jan, 2008
Posts: 8

aaah, any tips then on using C# on a mac?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Converting C# To C
3 Jan, 2008 - 10:36 PM
Post #7

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
C# was built targeting the .NET framework. The .NET framework targets Windows. Thus to get it on the Mac you will need to be able to install the framework and one of the popular ways of doing that is through the use of Mono.

Mono Project

Another alternative rising up here is dotGNU which is a project attempting to replace .NET for other systems and offer it for free.

dotGNU website

There might be a few other projects out there that can help you but these are the two that come off the top of my head for developing C# on systems other than Windows.

Hope these help. Enjoy! smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 03:49PM

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