Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Command-line using Dev-C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
18 replies to this topic

#1 Carolina   Members   -  Reputation: 176

Like
0Likes
Like

Posted 27 June 2005 - 08:32 AM

Hi there! I´d like to know how can I use command line in Dev-C++.I´m making a program that uses argc and argv[].However,I have no idea how can I call the program using Windows.My compiler is Dev-C++.Any ideas? Carol

Sponsor:

#2 SlippyPulse   Members   -  Reputation: 100

Like
0Likes
Like

Posted 27 June 2005 - 08:50 AM

Hey, i used dev cpp and i didn't have a compiler so i got borland c++ compiler. Borland is a command-line compiler and it works. Try borland, it might help, I dont know if it will work for your program because i just used it on a simple program i made. Hope this helps!

#3 Rayno   Members   -  Reputation: 511

Like
0Likes
Like

Posted 27 June 2005 - 08:50 AM

I haven't really used dev-c++, but I know it uses the MinGW compiler. Which is a windows port of gcc. So to compile stuff, you just type the command "gcc". Type "gcc --help" to learn how to use it. More commonly you use makefiles and run the "make" command (again "make --help" will tell you how to use it). I don't know if dev-c++ auto-generates make files, or what.

If non of those commands work, it means that you have to add the directory that they reside to your "path" variable. To do this on XP:
Right click My Computer,
click properties,
go to the "Advanced" tab,
click "Enviroment Variables",
Edit the "Path" variables under "System variables",
add ";c:\mingw\bin", or wherever its installed in (just search for gcc.exe, or make.exe).

#4 xidis   Members   -  Reputation: 127

Like
0Likes
Like

Posted 27 June 2005 - 09:52 AM

There is an option to set parameters (I forget exactly what its called or what menu roll out its in) but the option will let you pass commands to argv. Its built into dev-cpp.

#5 Rayno   Members   -  Reputation: 511

Like
0Likes
Like

Posted 27 June 2005 - 09:59 AM

Oh, ha! I guess I misunderstood the question. Sorry.

#6 sSimontis   Members   -  Reputation: 100

Like
0Likes
Like

Posted 27 June 2005 - 10:02 AM

I'm not sure what your asking, a lot of people seem to be thinking that you are talking about calling the compiler from the command line. However, if you are wondering how you run the program so that you can add the arguments, you simply go to the command line. On Windows 2000/XP, Go to Start->Run and type in 'cmd' without the quotes. On 9x/ME, type in 'command' without the quotes. You then just need to navigate to the directory where your program is, through the cd command, and then you just run your program with the arguments after the program name.
Scott SimontisMy political blog

#7 Kim Jong Il   Members   -  Reputation: 264

Like
0Likes
Like

Posted 27 June 2005 - 10:05 AM

Or, you can open your project, and go to Execute -> Parameters and type in the parameters you want into the little box that appears.

That has the same effect, but from within the IDE without you having to open Command Prompt and do all the dirty work yourself.

HTH,

ukdeveloper.

#8 thannett   Members   -  Reputation: 214

Like
0Likes
Like

Posted 27 June 2005 - 10:10 AM

Or you can right click the compiled executable, click create shortcut. Then right click the shortcut, go to properties, then add your parameters to the end of the Target field.

#9 Carolina   Members   -  Reputation: 176

Like
0Likes
Like

Posted 27 June 2005 - 11:15 AM

Thanks for the replies! I still haven´t solved my problem...I mean,now I´m using the DOS-Prompt to have the program activated,like this:
C:\Documents and Settings\User>Desktop\simulator 10 5 fatorial.asm

My program is a CPU processor simulator and reads some data from a file(in this case,fatorial.asm,which is a parameter).The parameters 10 and 5 are sizes of vectors I use later in the program.Anyway,the problem is, the program doesn´t work and I have a guess it is because of this command:

FILE *fp=fopen(argv[3],"r");

This is the command I use to read the file name from argv[3] and open the "fatorial.asm" file. The program goes fine up to this command,then it stops.And YEAH,´the file exists and is in the same directory as the executable file.So,what should I do? Y.Y

Thanks a lot!

#10 Carolina   Members   -  Reputation: 176

Like
0Likes
Like

Posted 27 June 2005 - 11:18 AM

Hey,I´ve tested using the Execute->Parameters of Dev-C++ and it works fine...Why the hell DOS-Prompt doesn´t?¬¬

#11 MSalley   Members   -  Reputation: 109

Like
0Likes
Like

Posted 27 June 2005 - 04:13 PM

Quote:
Original post by SlippyPulse
Hey, i used dev cpp and i didn't have a compiler


Dev Cpp is a compiler too. Click on the "execute" menu and then click "compile and run."

May the force be with you. All of you.
-Mat² §alley©-

#12 Raduprv   Members   -  Reputation: 997

Like
0Likes
Like

Posted 27 June 2005 - 04:37 PM

Quote:
Original post by MSalley
Dev Cpp is a compiler too. Click on the "execute" menu and then click "compile and run."


No, it isn't a compiler. It's an IDE. But you can download it with a compiler (gcc).

To answer the original question:
Add this at the beginning of your program:
printf("Here is what argument 3 is: %s",argv[3]);
Then see what it says.

#13 Icefox   Members   -  Reputation: 238

Like
0Likes
Like

Posted 27 June 2005 - 09:21 PM

Quote:
Original post by Raduprv
Add this at the beginning of your program:
printf("Here is what argument 3 is: %s",argv[3]);
Then see what it says.


Probably something along the lines of "Segmentation fault: core dumped" if you don't make sure it has that many arguments...

#14 Carolina   Members   -  Reputation: 176

Like
0Likes
Like

Posted 28 June 2005 - 04:43 AM

Hi!

The program is working fine now,when I use Dev-C++ and insert parameters before compiling(through Execute->Parameters).But now I´ve got another(simpler ^_^) question: how can I count written lines from a file?I was thinking about using fscanf(filename,"%c\n",&character) and then verifying if the result is a letter(since all the written lines at the file start with a letter).If it is,then a counter would be incremented,corresponding to the number of lines. Is this a possible solution?What you guys think?

Thanks again,

Carol

#15 chad_420   Members   -  Reputation: 290

Like
0Likes
Like

Posted 28 June 2005 - 06:26 AM


#include <fstream>

#define MAX_LENGTH 255
//MAX_LENGTH is the length of the longest line in your file or longer.

ifstream file;
file.open("whatever.wht");

int ctr = 0;
char *t[MAX_LENGTH];

while(!file.eof())
{
file.getline(t, MAX_LENGTH);
ctr++;
}



That will probably work to count lines in a file.

#16 Carolina   Members   -  Reputation: 176

Like
0Likes
Like

Posted 28 June 2005 - 12:27 PM

Huh...I dunno,I´ve never used this fstream header.Is ifstream a variable type?Does it work like a pointer to a file?I´ve searched around my Dev-Cpp directory and there´s no fstream file at the Include folder

But thanks anyway,I´ll adapt your idea^^

#17 darklordsatan   Members   -  Reputation: 258

Like
0Likes
Like

Posted 28 June 2005 - 05:43 PM

Well, fstream.h should be here
C:\Dev-Cpp\include\c++\3.3.1\backward\fstream.h

Ifstream is basically a "File input stream class"


ifstream file;


So file, is an instance of that class

#18 Zahlman   Moderators   -  Reputation: 1682

Like
0Likes
Like

Posted 28 June 2005 - 10:59 PM

If you look around a bit more you should be able to find the proper "fstream" file (no .h) too :) (I don't have Dev-cpp so I can't tell you exactly where, sorry.) Anyway, the ifstream object is simply the C++ version of FILE* - although cleaned up a fair bit.

Of course, if we're going to use C++ we may as well *really* use C++:


// In C++ we should use const identifiers for constants rather than #defines
// where possible: thus, "const int MAX_LENGTH = 255;"
// However, we won't need this value anyway :)

#include <fstream>
// Note that new C++ headers place all this stuff in the std namespace.
// fstream.h does not, but it's a backwards-compatibility hack for old code and
// should not be used these days (marked deprecated).
#include <limits> // for version A
#include <string> // for version B

// The ifstream offers a constructor accepting the same parameters as a .open()
// call, so in the normal case we may as well use it directly
std::ifstream file("whatever.wht");

int counter = 0;
std::string buffer; // for version B

// VERSION A
while(file.ignore(std::numeric_limits<streamsize>::max(), '\n')) { counter++; }
// I think I "spelled" all of that correctly. We "ignore" (skip past) lines
// until the return value (which is '*this' - i.e. 'file') evaluates false
// (which happens at end of file, or if there is some other serious problem).

// VERSION B
while(std::getline(file, buffer)) { counter++; }
// Similarly, we read lines into a string (that will resize itself appropriately
// regardless of the data) until EOF.



Someone else is sure to come along now and redo this in functional style ;s

#19 Carolina   Members   -  Reputation: 176

Like
0Likes
Like

Posted 02 July 2005 - 01:07 PM

Thanks,Ipve found the fstream header already^^




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS