main(int argc, char *argv[])

I have a Threshold.cpp which contains the above main function

main(int argc, char *argv[])

The teacher wanted us to create an exe using the command line and then use it:

Ex:
make Threshold
-> creates Threshold.exe
Threshold imageIN.pmg ImageOut.pmg
-> does someting to imageIN and outputs it in ImageOut.

My question is, how do I use it in visual studio? I'm used to an empty main() and all I have to do is build it and an .exe will pop out. However, it doesn't work this time. The error I get is:

Threshold.exe not found or not built by the last incremental link; performing full link
Embedding manifest...

Anyone has any idea on how I can do it with visual studio?

Thanks much!
I am sorry, but i do not want to know about microsoft, jejejejejeej.
Sorry, i am jocker.
No, i can not help you. In pure c++ i may help you, but in VS i do not have any idea.
That's not an error...are you sure that is the only message you are getting?

@socket2008: If you aren't going to contribute, don't post. kthxbai
Last edited on
argc is the number of argument strings in the argv[] array.

Here's an example to get you started:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iomanip>
#include <iostream>
using namespace std;

int main( int argc, char* argv[] )
  {
  cout << "The name used to start the program: " << argv[ 0 ]
       << "\nArguments are:\n";
  for (int n = 1; n < argc; n++)
    cout << setw( 2 ) << n << ": " << argv[ n ] << '\n';
  return 0;
  }

Compile it, then from the command-prompt try running it different ways:

D:\prog\test> a Hello world!
The name used to start the program: a
Arguments are:
1: Hello
2: world!

D:\prog\test> cd ..

D:\prog> test\a.exe "Peter Piper" picked a peck of "pickled peppers"
The name used to start the program: test\a.exe
Arguments are:
1: Peter Piper
2: picked
3: a
4: peck
5: of
6: pickled peppers

And so on. Hope this helps.
I'm getting a debug assertion error from dbghook.c. That is when I start do debug it (F5). If I try to build it, the message I get is:

------ Build started: Project: 3090Hw5Threshold, Configuration: Debug Win32 ------
Compiling...
Threshold.cpp
Linking...
Embedding manifest...
Build log was saved at "file://c:\Documents and Settings\Ky\My Documents\Visual Studio 2008\Projects\3090Hw5ThresholdSolution\3090Hw5Threshold\Debug\BuildLog.htm"
3090Hw5Threshold - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


It says 1 succeeded but I don't see a Threshold.exe after I build it. Threshold.cpp has this code segment:

#include <iostream>
#include <fstream>

#include "image.h"

using namespace std;

int readImageHeader(char[], int&, int&, int&, bool&);
int readImage(char[], ImageType&);
int writeImage(char[], ImageType&);

int main(int argc, char *argv[])
{
int i, j;
int M, N, Q;
bool type;
int val;
int thresh;

// read image header
readImageHeader(argv[1], N, M, Q, type);

// allocate memory for the image array
ImageType image(N, M, Q);

// read image
readImage(argv[1], image);

cout << "Enter threshold: ";
cin >> thresh;

// threshold image

for(i=0; i<N; i++)
for(j=0; j<M; j++) {
image.getPixelVal(i, j, val);
if(val < thresh)
image.setPixelVal(i, j, 255);
else
image.setPixelVal(i, j, 0);
}

// write image
writeImage(argv[2], image);
return (1);
}

Inside the main, it uses argc and *argv[] and I need to call it from the console like what Duoas displayed. However, I can't even compile/build it. It works with the make command of linux though so the code is fine. Eventually, I will want to hard code the main such that it'll take imageIN and output imageOUT automatically since I'll be testing it a lot.

Ex: main( ImageToProcess, ImageAfterProcessing)
Um, I don't think you can do that with main()...you will have to use argv to handle that...Anyway, are you looking in the directory where it is built? There should be a Debug or Release folder that the .exe is stored in.
Actually I do find the .exe. Thanks.
Topic archived. No new replies allowed.