loops and arrays

This is a discussion on loops and arrays within the C Programming forums, part of the General Programming Boards category; please help with this code. dont want to see numbers in the array file_nums. int num_files,file_nums[25],loop; printf("input amount of files:>"); ...

  1. #1
    Unregistered
    Guest

    Angry loops and arrays

    please help with this code.

    dont want to see numbers in the array file_nums.


    int num_files,file_nums[25],loop;

    printf("input amount of files:>");
    scanf("%d",&num_files);

    for(loop=0;loop<num_files;loop++)
    {
    scanf("%d",&file_nums[loop];
    }

    for(num=0;num<fnumber;num++) /* fnumber=3 */
    {
    int seen=0;

    for(loop=0;loop<num;loop++)
    {
    if(file_nums[loop]==file_nums[num])
    {
    seen=1;
    break;
    }

    if(!seen) printf("%d",num_files[num]);

    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    Too many brackets.

  3. #3
    Unregistered
    Guest
    You mean too few. This is the same code formatted as closely as I could figure.
    Code:
    int num_files, file_nums[25] = '0', loop; 
    
    printf("input amount of files:> "); 
    scanf("%d",&num_files); 
    
    for(loop=0;loop<num_files;loop++) 
    { 
        scanf("%d",&file_nums[loop];  /*how do I know what to do?*/
    } 
    
    for(num=0;num<fnumber;num++)  /* fnumber=3 */  //fnumber means?
    { 
        int seen=0; 
    
        for(loop=0;loop<num;loop++) 
        { 
            if(file_nums[loop] == file_nums[num])  /*huh? tell me what's happening here*/
            { 
                seen=1; 
                break; 
            } 
            if(seen != 0)   /* be explicit */ 
                printf("%d",num_files[num]);
        } /*you forgot this bracket*/
    }
    This is very twisted code, if there's any doubt as to whether or not the reader will understand on the first pass, be sure to comment it. Your loop structure is very hard to follow since each loop's testing condition is based on the counter for the previous loop.

    Out of curiosity, what are you trying to do with this code? I can't figure it out.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    dude, you are right. Sorry about that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using arrays and loops for math
    By LLINE in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2008, 05:09 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  3. while loops with arrays
    By volk in forum C Programming
    Replies: 2
    Last Post: 02-04-2003, 07:22 PM
  4. Arrays and loops
    By Zewu in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2002, 12:05 PM
  5. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21