i have this code:

int main(int argc, char* argv[])
{
   remove(debug_file);

    count=0;//count d number of seeding
    for (int i = 1; i < argc; i++)
       {
	/* Check for a switch (leading "-") */

	if (argv[i][0] == '-')
	  {
	     /* Use the next character to decide what to do. */

	     switch (argv[i][1])
	      {

		case 'i':  strcpy (input_file,argv[++i]);
			   printf ("Input file =  %s\n", input_file);
			   break;
                case 'o':  strcpy (output_file,argv[++i]);
			   printf ("Output file =  %s\n", output_file);
			   break;

                            
               case 's':   strcpy (seed,argv[++i]);
                           strcpy (seed_array[count],seed);
                           seeding();
                           count++;
                           break;
                          


            default:   printf ("Invalid selection \n");
                       break;
	   }
	}
    }

   CleanUp();
   printf ("Running Completed......\n");
   getch();

   return 0;
}

lets say i have this parameter:
-i fruit.flt -o out -t 2 -s flower, -s oren, -s banana,

there r 3 type of seeds:flower,oren and banana which r need to be written in output file.before that, i have to process the data in seeding() function.because of the system found 3 times of -s, the function seeding() entered 3 times.what should i do if i want the system enter the function seeding() only once after the 3rd -s (banana) is processed.means,when count=3 then only go to fucntion seeding().

really blur

Recommended Answers

All 8 Replies

Don't put it in the switch.

Don't put it in the switch.

so, if else is better in my case?
could u please explain a bit about it?because im a new leaner.really need help

You can call the function immediately before you call cleanup either by itself or after checking for count.

You can call the function immediately before you call cleanup either by itself or after checking for count.

i have no idea at all,seriously!!!

What I meant was:

comment out seeding() on line 27.

Add the following on line 38

if(count)
{
       seeding();

}

What I meant was:

comment out seeding() on line 27.

Add the following on line 38

if(count)
{
       seeding();

}

this means i'll seeding() everytime i found "-s" rite?but this is my problem.i want to call seeding() after the last "-s".but in this example,there r only 3 "-s", in real case its a random number of "-s".
any idea about this?

No. You will be calling seeding only after you have finished processing all your input parameters from command line.

Line 38 is outside the for loop where you are processing your command line parameters.

No. You will be calling seeding only after you have finished processing all your input parameters from command line.

Line 38 is outside the for loop where you are processing your command line parameters.

U r genius man!!!! thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.