[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Passing Argument

Asked by ExpExchHelp in C Programming Language, C++ Programming Language

I need some help with passing an argument from >> input << to >> output <<.

When this program is executed (from command window), the user must enter "name of executable", "image input filename" [1st argument], "image output filename" [2nd argument].

The programs then does do some "processing" (what it does is not pertaining to this question).

The the program sent feedback to screen ("You have successfully unhidden the image")  

Now, here's what I need some help with.  Instead of just indicating "image", I'd like to include the output filename that the user entered [2nd argument].    How do I pass that value from the input section to the fprintf statement at the bottom of the program?

Thanks,
EEH



************
// The main function has always access to the programs.
// argc = counter; argv = array of strings.
int main(int argc, char **argv){


      // Initialize variables:
        // ... done here


      // The read program is invoked by: readimage inputfile outputfile.
      // Program requires at least 3 arguments:
      // 1. "call program"
      // 2. "input pgm"
      // 3. "output pgm"; the modified image will be written to this outfile file

      if (argc < 3) {
            fprintf(stderr,"Usage: readimage input-file-name output-file-name\n");
            exit(0);
      }
      fpIn = fopen(argv[1],"rb");                        // argv[1] contains the filename
      if (fpIn == NULL) {
            fprintf(stderr,"%s either cannot be read or does not exist\n", argv[1]);
            exit(-1);
      }
      string = (char *) calloc(256,1);            // initialized dynamic memory allocation
      while (!doneReading && (c = (char) fgetc(fpIn)) != '\0')
      {
            switch(c) {
case 'P':
      c = (char) getc(fpIn);
      switch(c) {
case '2':
      numberOfBands = 1;
      // ppmType = PPMASCII;
      break;
case '3':
      numberOfBands = 3;
      // ppmType = PPMASCII;
      break;
case '5':
      numberOfBands = 1;
      // ppmType = PPMGRAY;
      break;
case '6':
      numberOfBands = 3;
      // ppmType = PPMRAW;
      break;
      }  

      c = (char) getc(fpIn);
      if (c != 0x0A) {
            ungetc(c,fpIn);
      }
      else {
            ungetc(c,fpIn);
            fgets(string,256,fpIn);
      }
      break;

case '#':
      fgets(string,256,fpIn);
      break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
      ungetc(c,fpIn);
      fscanf(fpIn,"%d %d %d", &numberOfColumns, &numberOfRows, &highVal);
      doneReading = TRUE;
      fgetc(fpIn);
      break;

            }    // End Switch
      }      // End While


      // Reads from the specified pointer; 1 byte, # of pixels, and file pointer
      image = (unsigned char *) malloc(totalPixels);
      l = fread(image,1,totalPixels,fpIn);
      fprintf(stderr,"fread returned %d bytes\n", l);
      imaged = (unsigned char *) malloc(totalPixels);


      // Some processing is performed here!


      // ******** Image Output Section ********
      //Generate the midterm2.pgm (modified) image
      fpOut = fopen(argv[2],"wb");

      // Write image header
      fprintf(fpOut,"P%d\n%d %d\n255\n",numberOfBands>1?6:5,numberOfColumns,numberOfRows);  
    fwrite(imaged,1,totalPixels,fpOut);          

// Feedback
fprintf(stdout,"\n\n\nYou have successfully unhidden the image!\n\n\n");                                            


      // Exit routine
      exit(0);  
 
Related Solutions
Keywords: Passing Argument
Title
1 C++ Function
 
Loading Advertisement...
 
[+][-]11/01/07 07:13 PM, ID: 20197950Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C Programming Language, C++ Programming Language
Sign Up Now!
Solution Provided By: NickGeorghiou
Participating Experts: 3
Solution Grade: A
 
[+][-]11/01/07 07:48 PM, ID: 20198085Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/01/07 07:48 PM, ID: 20198088Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/01/07 08:35 PM, ID: 20198285Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/01/07 09:15 PM, ID: 20198397Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/01/07 11:01 PM, ID: 20198618Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628