Where should I put the semi-colons, I don't understand it.

Ok, here's my code as below but I am getting errors about missing ';' before the ')'.
I've worked in vb.net and no such problem would exist in vb.
Anyway, I don't really know if what I've written up to now is correct or not as the program is incomplete, but the thing is I can't test how I'm doing up to now due to the missing semi-colons problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "stdafx.h"
#include "stdio.h"
#include <conio.h>

int _tmain(int argc, _TCHAR* argv[])
{
int n = 0;
scanf("%d", &n);
int *a = 0; 
a = new int[n];

int m = 0;
scanf("%d", &m);
int *b = 0; 
b = new int[m];

int temp, i;

scanf("%d", &a[n]);
scanf("%d", &b[m]);

   if (n < m) 
{
	for (i=0, i <m, i++) 
	{
		temp = i;
			for (i=0, i<n, i++)
			{
				if (a[i] = b[temp]);
				{
					if (a[i+1] = b[temp+1]);
					{
						printf("there are 2 consecutive elements in the a and b arrays");    
					}
				}
			}
	}
}



a = 0;
b = 0;
getch();
return 0;
    }
Last edited on
for (i=0, i <m, i++){
Becomes
for (i=0; i <m; i++){
same for the other for loop.
if (a[i] = b[temp]){
becomes
if (a[i] == b[temp]){
same for the other if.
1
2
scanf("%d", &a[n]);
scanf("%d", &b[m]);

Segmentation Fault. Or you ask n/m times for a single value, or you don't need at all to "new" the arrays.
1
2
scanf("%d", &a[n-1]);
scanf("%d", &b[m-1]);

removes the segfaults if you want to run your code and see what it does.
1
2
scanf("%d", &a[n-1]);
scanf("%d", &b[m-1]);


Hmm, I just googled about dynamic declaration of array size and got that code somewhere but it seems I've gotten it wrong, I can compile it even without those two fixes that you mentioned, I had to fix the previous errors. But what happens after compiling the program is that I scan the n&m values, I input the a[n] elements one by one but I can't put the b[m] elements as the program goes straight to the getch() code.
1
2
scanf("%d", &a[n-1]);
scanf("%d", &b[m-1]);

This is the problem:
This code only asks for ONE number to store into a[n-1], and ONE number into b[m-1].
So you need to LOOP from 0 to n-1, and to store each value correctly.
I understand it now, TYVM for your help, I shall try to clear out the rest now, thanks again.
Topic archived. No new replies allowed.