Find the answer to your Linux question:
Results 1 to 8 of 8
Hello , I have got a question .... I have a program written in LINUX C coding, Im an amatuer, so I donno exactly HOW CAN I CHANGE THAT CODING ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Posts
    3

    Question changing linux coding to C

    Hello , I have got a question ....

    I have a program written in LINUX C coding, Im an amatuer, so I donno exactly HOW CAN I CHANGE THAT CODING TO WINDOWS C COMPILER ...

    is there anyone who could help me ?

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    That depends on what kind of program it is. If it's just a simple command-line program you shouldn't have to change your code at all; just recompile it using a Linux compiler like gcc. What sort of program is it?
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Just Joined!
    Join Date
    Dec 2007
    Posts
    3

    Smile

    oh, thank you so much for helping!

    this program is the CONWAY'S LIFE GAME MODEL , which i have to submit it with perfect coding , i wish I could send u the coding, so u could help me more...

  4. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Try it. Take your source code and run it through the GCC or G++ compiler (depending on what it's written in). If it runs, you're good. If it gives you errors, post them back here and we'll do our best to work you through them.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  5. #5
    Just Joined!
    Join Date
    Dec 2007
    Posts
    3
    to be honest i have already done it,,, but because im kind of amateur i cannot make it ok.

    #include <stdio.h>
    #include <stdlib.h>
    #include <X11/Xlib.h>
    #include <X11/Xutil.h>

    #define HMAX 500
    #define VMAX 500

    Display *d;
    Window w;
    GC gc;
    int fg, bg;

    char bitmap[2][HMAX][VMAX];
    int hsize, vsize, psize, cbn;


    void bgpixel_show(int i, int j)
    {
    XSetForeground(d, gc, bg);
    XFillRectangle(d, w, gc,
    (i-1)*psize, (j-1)*psize,
    psize-1, psize-1);
    }


    void fgpixel_show(int i, int j)
    {
    XSetForeground(d, gc, fg);
    XFillRectangle(d, w, gc,
    (i-1)*psize, (j-1)*psize,
    psize-1, psize-1);
    }


    void pixel(int c, int i, int j)
    {
    if (c<2 || c>3)
    {
    bitmap[1-cbn][i][j] = 0;
    bgpixel_show(i,j);
    return;
    }
    if (c==3)
    {
    bitmap[1-cbn][i][j] = 1;
    fgpixel_show(i,j);
    return;
    }
    bitmap[1-cbn][i][j] = bitmap[cbn][i][j];
    }


    bitmap_init()
    {
    int i,j;

    for (i=1; i<=hsize; i++)
    for(j=1; j<=vsize; j++)
    if (bitmap[cbn][i][j] = rand() %2)
    fgpixel_show(i,j);
    else
    bgpixel_show(i,j);

    for (i=0; i<=hsize+1; i++)
    {
    bitmap[cbn][i][0] = 0;
    bitmap[1-cbn][i][0] = 0;
    bitmap[cbn][i][vsize+1] = 0;
    bitmap[1-cbn][i][vsize+1] = 0;
    }
    for (j=0; j<=vsize+1; j++)
    {
    bitmap[cbn][0][j] = 0;
    bitmap[1-cbn][0][j] = 0;
    bitmap[cbn][hsize+1][j] = 0;
    bitmap[1-cbn][hsize+1][j] = 0;
    }
    }


    bitmap_next()
    {
    int i,j;
    int c;

    for (i=1; i<=hsize; i++)
    for(j=1; j<=vsize; j++)
    {
    c = bitmap[cbn][i-1][j-1] + bitmap[cbn][i-1][j]
    + bitmap[cbn][i-1][j+1] + bitmap[cbn][i][j-1]
    + bitmap[cbn][i][j+1] + bitmap[cbn][i+1][j-1]
    + bitmap[cbn][i+1][j] + bitmap[cbn][i+1][j+1];
    pixel(c,i,j);
    }
    cbn = 1-cbn;
    }


    void event_loop()
    {
    XEvent e;
    while(1) {
    XNextEvent(d, &e);
    switch (e.type) {
    case KeyPress:
    while(1)
    bitmap_next();
    default:
    break;
    }
    }
    }


    void window_init()
    {
    XGCValues gcv;

    if((d=XOpenDisplay(NULL))==NULL)
    {
    exit(-1);
    }

    bg = WhitePixel(d,DefaultScreen(d));
    fg = BlackPixel(d,DefaultScreen(d));

    w = XCreateSimpleWindow(d, RootWindow(d,DefaultScreen(d)),
    0, 0, psize * hsize, psize * hsize,
    2, fg, bg);

    gcv.function = GXcopy;
    gcv.foreground = bg;
    gcv.background = fg;
    gc = XCreateGC(d, w,
    GCFunction | GCForeground | GCBackground,
    &gcv);

    XMapWindow(d,w);
    XSelectInput(d,w,
    EnterWindowMask | LeaveWindowMask | ButtonPressMask |
    OwnerGrabButtonMask | ExposureMask | StructureNotifyMask |
    KeyPressMask);
    }


    void main()
    {
    hsize = 200;
    vsize = 200;
    psize = 4;
    cbn = 0;
    window_init();
    bitmap_init();
    event_loop();
    }

  6. #6
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I'll be a bit more specific.

    So the C compiler that we use in Linux is called gcc (stands for "GNU Compiler Collection"). Using it is rather simple:
    Code:
    gcc foo.c
    This will compile the file "foo.c" and produce an executable file called "a.out" that you can execute to run the program.

    So let's suppose that your source file is called "conway.c", you want to show warnings, and you want to call the executable file "conway":
    Code:
    gcc -Wall -o conway conway.c
    This will either produce a file called "conway" (which you can then execute to run the program), or produce some errors that you will need to fix. If you don't understand the errors, please feel free to post them here and we'll try to help.

    One note on your program: the main() function should never return void. It should always return an int, and that int should be 0 if the program ran successfully, or nonzero if there was a problem somewhere. I suggest you change it to:
    Code:
    int main()
    {
        ...
        return 0;
    }
    DISTRO=Arch
    Registered Linux User #388732

  7. #7
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    You're importing two X11 libraries at the very top. Those do not exist in Microsoft Windows as far as I know. That's your first problem.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  8. #8
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Wait...I'm very confused all of a sudden.

    You have this program that runs successfully on Linux, but you want it to run on Windows instead?

    In that case, you're going to need to compile it using a Windows C compiler (I don't believe gcc can produce Windows executables?), and change all of your code that refers to Linux things (for instance, the X server). The details of doing that can maybe be discovered online, but you may just need to surf through the Windows libraries to find equivalent functions.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...