Thread: Compiler

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Question Compiler

    I have Linux running on a 32MB computer.
    I have Win200 on a256MB computer.
    The Win2000 computer has the Miracle C compiler.
    The Linux computer has a compiler-but I do not know which one(i do not know how to find out).

    The following program,runs ok with Miracle C but does not run on the Linux Computer.Kindly advise.
    Program#1
    -----------------------------
    /* Averages five float values entered by the user. */

    #include <stdio.h>

    float v, w, x, y, z, answer;

    float average(float a, float b, float c, float d, float e);

    main()
    {
    puts("Enter five numbers:");
    scanf("%f%f%f%f%f", &v, &w, &x, &y, &z);

    answer = average(v, w, x, y, z);

    printf("The average is %f.\n", answer);

    return 0;
    }

    float average( float a, float b, float c, float d, float e)
    {
    return ((a+b+c+d+e)/5);
    }

    -----------------------------------
    Many Thanks
    csick

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Did you just take the compiled file from windows and put it in Linux and try and run it? If you did, it doesn't work that way. The compiler grabs certain resources from the operating system.

    You will have to take your code and compile it in Linux.

    Most Linux boxes come with cc/gcc. Go to the shell or a xterm and type: man cc or man gcc. Read about using them.

    Good luck

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    5
    Actually I compiled the code in Linux using cc average.c -o average
    .I don't know what could be the problem.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    try typing dos2unix <filename>.c

    then type gcc <filename>.c

    see what happens then.

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > dos2unix <filename>.c

    In Solaris it's dos2unix source.c dest.c - Is it different in Linux?

  6. #6
    Unregistered
    Guest
    In a console try :

    gcc -v <ENTER>

    so you will know if your compiler is gcc.

    Try too "cc -v"

    cc is a a symlink to gcc.


    Then type :

    gcc -o myprogramname myfilename.c <ENTER>

    If your file is average.c you can for example type :

    gcc -o average average.c <ENTER>

    You get then an executable called average.

    Try it with:

    ./average <ENTER>

    It will run.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Originally posted by Govtcheez
    > dos2unix <filename>.c

    In Solaris it's dos2unix source.c dest.c - Is it different in Linux?
    i guess

  8. #8
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    I pasted your code into a text file named "test.c" and was able to compile it (in Linux) with the command:

    gcc -o test test.c
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM