i got the point but how can i merge the two arrays?
Printable View
i got the point but how can i merge the two arrays?
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.
i dont have a book about c language
where can i found basics?
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.
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
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.
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
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();
}
B[b]==NULL;
left side is integer, right side is a pointer - don't you get any warnings?
a is 5 and is increased with each a++ iteration - effectively scanning not initialized members of CQuote:
Code:for(b=0;b<5;b++)
{ if (B[b]!=NULL);
{ C[a]==B[b];
a++;
}
}
b is 5 so you have out of bounds access to B and also mixing pointer and integerCode:for(a=0;a<5;a++)
{ if (A[a]==B[b]);
{ B[b]==NULL; }
}
is equivalent toCode:C[b]>=0 && C[b]>=1000
C[b]>=1000
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? :devil:
nope i dontQuote:
B[b]==NULL;
left side is integer, right side is a pointer - don't you get any warnings?
oops sorry i mistyped it shoulde beQuote:
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
Code:C[b]>=0 && C[b]<=1000
tomorrow =(