i got the point but how can i merge the two arrays?
i got the point but how can i merge the two arrays?
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
A typical example of ...cheap programming practices.Code:... goto johny_walker_red_label; johny_walker_blue_label: exit(-149$); johny_walker_red_label : exit( -22$);
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 CCode: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
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
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"
nope i dontB[b]==NULL;
left side is integer, right side is a pointer - don't you get any warnings?
oops sorry i mistyped it shoulde beb 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 =(