hello ive got 2 arrays defined below

char RW[100];

char array[80];

ive got this algo for now but not 100% certain its working

void setI(char array[])
	cout << "now in seti function" << endl;

	for (int j = 0 ; j <=sizeof(RW[j]); j++)
		for (int i = 0 ; i <=sizeof(array[i]); i++)
		strcmp(&array[i], &RW[j]);

the problem is that the strcmp is not comparing all results plus its always returning true. Any suggestings on makeing it more effective and efficient?



12 Years
Discussion Span
Last Post by dwks

How about you explain what you're trying to do? My first impression is that your code is broken due to several misconceptions about how strings work.

>for (int j = 0 ; j <=sizeof(RW[j]); j++)
sizeof RW[j] is 1. Always.

>for (int i = 0 ; i <=sizeof(array); i++)
sizeof array is 1. Always.

>strcmp(&array, &RW[j]);
There's a very good chance that this doesn't do what you think it does.


Hello sorry for my none explantation, here it goes... Ive got 2 popluated arrays...

array = "a+b*c;
RW = "+*;"

I want to scan or go through and compared array to RW and if the characters that dont exisit in RW i put them into a 3rd array. I hope that makes sence?


scan 1 takes 'a' ...is a in RW[0] = No
is a in RW[1] = NO
is a in RW[2] = NO
{reached null, put a into ID (another created array)
scan 2 takes +     is + in RW[0] = YES increment RW[0] so it alwats starts at 1
scan 3 takes b .... and so on

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.