Author Topic: help  (Read 12151 times)

Cman

  • User
  • *
  • Posts: 9
help
« on: February 15, 2005, 09:04:36 PM »
I just downloaded a c\c++ compiler so i could try out programming in c
but i cant figure out how to save the file so the compiler will compile it.
I keep getting some error message like "file format not recognized; treating as linker script
"yeah, i know basic BASIC"

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
help
« Reply #1 on: February 16, 2005, 09:40:47 AM »
You have to give us more information than that, like what compiler you downloaded and what you did.

Typically if you are programming in C, you save the file with a .c extension, and for C++ code, a .cpp extension.  In all of the compiler's I've used that is sufficient for the compiler to recognize the language type and compile appropriately.

You need to tell us three things:
[list=1]
  • What compiler are you using
  • How did you save the file
  • What command did you use (or what action did you take) to try to compile the file.
  • [/list:o]
Gillius
Gillius's Programming http://www.gillius.org/

Cman

  • User
  • *
  • Posts: 9
help
« Reply #2 on: February 16, 2005, 05:26:26 PM »
1. MinGW - minimalist for windows
2. as a .txt file
3. i tried the .exe's called "c++.exe" and "mingw32-c++.exe"

but think your information solved my problem
thanks a bunch
"yeah, i know basic BASIC"

Cman

  • User
  • *
  • Posts: 9
help
« Reply #3 on: February 17, 2005, 02:09:02 PM »
Now its letting me input the file but it doesnt do anything
i just get on blank line on the command line and then he normal
C:\mingw\bin\>

am i doing something wrong or what
"yeah, i know basic BASIC"

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
help
« Reply #4 on: February 17, 2005, 05:49:57 PM »
It may not say anything if it generated the program properly.

What was the whole script?  You should done something like
Code: [Select]

gpp -o myprog.exe myprog.cpp

and you may not have seen any output but you would see myprog.exe appear.

You might want to try using something like Dev-C++ to work with MinGW so you don't have to use it from the command line.  Dev-C++ is a graphical environment that includes MinGW.

http://www.bloodshed.net/devcpp.html
Gillius
Gillius's Programming http://www.gillius.org/

Cman

  • User
  • *
  • Posts: 9
help
« Reply #5 on: February 17, 2005, 06:58:36 PM »
ill try that out
thank you so much for the help i never would
have figured this out without ur help

also when i ran the test.exe file i created i got an error saying that msdos had encountered an illegal instruction(i was running thru the windows command promt) all that it was is a program that is supposed to print "hello world! on the screen

does the dev-c++ thing create windows apps?(like win32 i think, so windows opens then instead of dos)
"yeah, i know basic BASIC"

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
help
« Reply #6 on: February 17, 2005, 11:45:25 PM »
When you say MSDOS you probably really mean Win32 console applications, which are truly 100% windows-only applications that run inside of a command prompt.  DOS programs are much older and need to be emulated in NT kernels like 2000 and XP.

Truthfully the only differences between a console application and one that's a "Win32 application" is that the console version uses by default "main" as its entry point, and the other WinMain with a different signature, and that a console application will open a console window while a Win32 application neither opens nor shows anything unless you program it too -- but you could even program it to open up a console if you wanted.

MingW32 can make both console and non-console types of programs.  I have not used Dev-C++ for several years, and even then only briefly did I evaluate it, but I would be extremely surprised if it did not offer an option to choose between the two since it differs only by a simple command line option to MinGW.
Gillius
Gillius's Programming http://www.gillius.org/

Cman

  • User
  • *
  • Posts: 9
help
« Reply #7 on: February 18, 2005, 11:16:44 PM »
dev-c++ does have an option to choose between comsole and non-console. but when i use the non-console option and try to compile and ru, it just compiles and opens a blank window. so if you could give me an example of the programming difference it would be greatly appreciated.
"yeah, i know basic BASIC"

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
help
« Reply #8 on: February 19, 2005, 03:36:56 PM »
A console application maps standard (as with printf and cout) output and standard error (as with cerr and fprintf(stderr,...)) to a console window.  And example of a Win32 console application is the "cmd" command line program from Windows NT-XP, and the command line-based compiler that comes with MinGW.

A Win32 application ignores standard output and standard error.  Unless you open a window or something in a Win32 application, you won't see anything.  An example is Internet Explorer, which does not have a console but opens up a window so the user can interact with the program.  Another example is the Dev-C++ application itself.  There is not a requirement to open up a window; there are processes in Windows that run in the background without a window, or only with a system tray icon.
Gillius
Gillius's Programming http://www.gillius.org/

Cman

  • User
  • *
  • Posts: 9
help
« Reply #9 on: February 20, 2005, 08:40:05 PM »
another thing i cant get right is IF statements. the program im trying to make prints a list of things at the top and it asks you to pick one, by entering the number it is on the list. The problem occurs when i put an ELSE in the program after the first IF. it gives me and error about the ELSE.
          here is the code if my explanation is bad:

Code: [Select]
#include <cstdlib>
#include <iostream>

using namespace std;
int main() {
    char c;
    int sr;
    int cr;
    int e;
    cout << "  1. Circle  " <<endl;
    cout << "  2. Sphere  " <<endl;
    cout << "             " <<endl;
    cout << "enter shape: " ;
     cin  >> c;
    if (c=1)
     cout << "Enter Radius: " ;
      cin  >> cr;
     cout << "             " <<endl;
     cout <<" Diameter        : " << cr*2 << endl;
     cout <<" Circumference   : " << 2*3.14*cr << endl;
     cout <<" Area            : " << cr*cr*3.14 << endl;
     cout <<"               " <<endl;
     cout <<" 1. Restart    " <<endl;
     cout <<" 2. Quit       " <<endl;
    if (c=2)
     cout <<"Enter Radius: " ;
     cin  >> sr;
     cout <<"              "<< endl;
     cout <<"Diameter          :"<< sr*2 << endl;
     cout <<"Circumference  :"<< 2*3.14*sr << endl;
     cout <<"Volume            :"<< sr*sr*sr*3.14*1.3333 << endl;
     cout <<"Surface Area    :"<< sr*sr*4*3.14 << endl;
     cout <<"               " <<endl;
     cout <<" 1. Restart    " <<endl;
     cout <<" 2. Quit       " <<endl; \\ i also cant figure out do...while loops
    return 0;
    }


keep in mind that this isnt finished
"yeah, i know basic BASIC"

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
help
« Reply #10 on: February 21, 2005, 11:58:46 AM »
You should put your code into code tags.  I edited your post to put them in there.

You need to understand braces.  C++ is not BASIC, and what defines the beginning and end of blocks are the braces {} and not whitespace or lines.

If you don't use braces, the if statement applies only to the statement immediately preceding.  So in the code you showed me, only the line "Enter Radius:" is covered by the "if (c=1)" statement.

Actually you have much worse problems, if you only have a single equal sign, then you are assigning the value of 1 to c, and the result of the if statement is always true, so in this program you show me, all lines are executed every time regardless of what the user inputs.

I seriously suggest that you brush up on the fundamentals of the language by getting a book.  I also have tutorials on my site that you can read to get some of this information.
Gillius
Gillius's Programming http://www.gillius.org/