Thread: can't get loop to increment

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    27

    can't get loop to increment

    the code below is part of my program. For some reason, I can't get the outermost for loop to increment. the outermost loop - for (i=1; i < file_len_suffix+1; i ++){ does not get incremented. what did i do wrong?

    Code:
    if (file_len_suffix>0){
    infile = fopen (file6suffixes, "r");
    outfile = fopen (filename4, "a");
    for (i=1; i < file_len_suffix+1; i ++){
        fscanf (infile, "%s", & cum_suffixes [i]);
        printf ("\n%s\n", & cum_suffixes [i]);
        suffixcomp = strncmp (cum_suffixes[i], the, 4);
            if (suffixcomp==0){
                for (i=1; i < file_len+1; i ++){
                    for (j=1; j <file_len_v+1; j++)
                        fprintf(outfile, "the %s %s.\n", cum_nouns[i], cum_verbs[j]);
                                                }
                               }
    
    suffixcomp = strncmp (cum_suffixes[i], to, 3);
             if (suffixcomp ==0){
                 for (i=1; i<file_len-1;i++){
                     for (j=1; j<file_len_v+1; j++)
                     fprintf(outfile, "%s %s to the %s", cum_nouns[i], cum_verbs[j], cum_nouns[i+1]);
                                            }
                                }
                                }
    fclose (infile);
    fclose (outfile);
                           }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Take a look at the outer and the first nested loop.... you're using the same variable (i).

    The outer i is known to the inner loop as well, each time the inner loop runs the outer one is set to the length of the file.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    THANK YOU! I just changed my inner loop variable to j and k, and it's working beautifully!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. increment iterator after loop
    By lawrenced in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2009, 08:51 AM
  2. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM