Thread: merging arrays

  1. #16
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    i got the point but how can i merge the two arrays?

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Correct your fundamental flaws first, I say. If you understand the basics, you should have no trouble merging them, especially not from all the explanations everyone has given you thus far.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    i dont have a book about c language
    where can i found basics?

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Books are the best bet. Tutorials are the next step.
    Without knowing the basics, you won't get anywhere in a language. It is critical that you understand the fundamentals. Just so you understand.
    What's a good book? There is a "recommended books" thread around here.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    hm..i dont have money to buy..im enrolled in a public open university thats why i visit this boards to gain some information to fill my lacks of having books

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ah yes, but not all books cost. Some you can get free from the internet and some may be available in some libraries.
    Otherwise you can try to rely on tutorials. They are the next best thing. Just try to find tutorials that deals with the basics and not specific examples or areas.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    i see, but i need to solve this problem now >_<
    next time ill probably read the tutorials.

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by acohrockz21 View Post
    i see, but i need to solve this problem now >_<
    If you understand the basics, you will understand how to solve it.
    Find yourself a nice tutorial explaining the basics, and when you grasp it, the tutorial will have solved your problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355

    Lightbulb

    Quote Originally Posted by acohrockz21 View Post
    i see, but i need to solve this problem now >_<
    next time ill probably read the tutorials.
    For the next time, and since you have no money (which really isn't that important for learning C as long as you have some patience and persistence) here is a nice site:
    C-ebooks
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  10. #25
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    hi
    currently i have form a code now but
    theres a problem when im printing

    the values of A and B are both printed
    it should be union of same values of A and B only

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int main()
    {
     int A[5],B[5],C[10];
     int a,b;
    
     clrscr();
     printf("Input 5 numbers\n");
     for(a=0;a<5;a++)
     { scanf("%d", &A[a]);
     }
     printf("Input 5 numbers to be merged\n");
     for(b=0;b<5;b++)
     { scanf("%d", &B[b]);
     }
     for(a=0;a<5;a++)
     { if (A[a]==B[b]);
       { B[b]==NULL; }
     }
    
     for(a=0;a<5;a++)
     { C[a]=A[a]; }
    
     for(b=0;b<5;b++)
     { if (B[b]!=NULL);
       { C[a]==B[b];
         a++;
       }
     }
      for(b=0;b<a;b++)
      { if (C[b]>=0 && C[b]>=1000)
       { printf("%d ", C[b]); }
      }
    
     getch();
    }

  11. #26
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    B[b]==NULL;
    left side is integer, right side is a pointer - don't you get any warnings?

    Code:
    for(b=0;b<5;b++)
     { if (B[b]!=NULL);
       { C[a]==B[b];
         a++;
       }
     }
    a is 5 and is increased with each a++ iteration - effectively scanning not initialized members of C

    Code:
    for(a=0;a<5;a++)
     { if (A[a]==B[b]);
       { B[b]==NULL; }
     }
    b is 5 so you have out of bounds access to B and also mixing pointer and integer

    Code:
    C[b]>=0 && C[b]>=1000
    is equivalent to
    C[b]>=1000
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  12. #27
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Hah, I just went to google a good tutorial on merging and came across the entire answer for you. It starts with two lots of 5 numbers, sorts each and then merges them into another array. The arrays are even called a b and c.

    Except their answer is wrong since it has "void main", and has two other really obvious bugs.

    Methinks I shouldn't post that tutorial yet. When is your assignment due anyway?
    Last edited by iMalc; 03-09-2008 at 02:15 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  13. #28
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    B[b]==NULL;
    left side is integer, right side is a pointer - don't you get any warnings?
    nope i dont


    b is 5 so you have out of bounds access to B and also mixing pointer and integer

    Code:

    C[b]>=0 && C[b]>=1000

    is equivalent to
    C[b]>=1000
    oops sorry i mistyped it shoulde be

    Code:
    C[b]>=0 && C[b]<=1000

  14. #29
    Registered User
    Join Date
    Feb 2008
    Posts
    18
    tomorrow =(

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  2. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  3. Merging two arrays.
    By Roaring_Tiger in forum C Programming
    Replies: 2
    Last Post: 08-21-2004, 07:00 AM
  4. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM
  5. merging arrays using pointers help!!!
    By edshaft in forum C++ Programming
    Replies: 3
    Last Post: 12-19-2001, 07:19 AM