didnt terminate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 19831030
    New Member
    • Jul 2007
    • 9

    didnt terminate

    I have send my code,It print some no without ending.but i cant found the fault point can u help me


    Code:
    #include <stdio.h>
    #include <string.h>
    	
    int main(int argc, char *argv[])
      {
    	int i;
    	int j;
    	int k;
    	int m;
    	int ptr;	
    k=0;
    printf("0");
    putchar('\n');
    	for(i=2;i<argc;i++)
       {
    	for (j=1;j<i;j++)
    	{	
    	ptr = strcmp(argv [j], argv[i]);
    	if(ptr==0)
    	{
    
    argv[i]=argv[i+1];
    i--;
    printf("%d",(j-1));
    //putchar('\n');
    goto loop;
    	}
    }
    {
    k++;
    printf("%d",k);
    loop:
    putchar('\n');
    }
    }
    return 0;
    }
    Last edited by 19831030; Jul 12 '07, 08:23 AM. Reason: word missing
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Originally posted by 19831030
    for(i=2;i<argc; i++)
    {
    etc...
    argc?

    That's the number of arguments on the command line. There must be at least 3 arguments or this loop will run forever.

    I do not understand your logic here. What are you trying to do?

    Comment

    • 19831030
      New Member
      • Jul 2007
      • 9

      #3
      Originally posted by weaknessforcats
      argc?

      That's the number of arguments on the command line. There must be at least 3 arguments or this loop will run forever.

      I do not understand your logic here. What are you trying to do?
      Hi!
      I enter arguments at the run time (./a.out {aa,bb,aa,cc,de ,dg,cc,cc,jhe}) like this.I use this code for numbered those string and if there are 2 or more string in same I wanna put a same index for that.So required o/p for above set is (0,1,0,2,3,4,2, 2,5) like this.Your help is highly appreciate & pls help me to solve this,bcos still I couldnt solve this.
      Thanks

      Comment

      • Darryl
        New Member
        • May 2007
        • 86

        #4
        Look at line 14, then look at line 23 above.

        i++ and i-- = loop forever!!!

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Also see this thread.

          kind regards,

          Jos

          Comment

          Working...