Thread: Comparing Arrays

  1. #1

    Question Comparing Arrays

    hi, i'm having trouble sorting 2 arrays..

    char array1[10];
    char array2[10];

    i want to print out all characters that exist in both array1 + array2, but not the elements that are not common..
    Please Help!

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    #include <stdio.h>
    #include <string.h>
    int main(void){
    char string1[] = "foobar";
    char string2[] = "flashdaddee";
    for(unsigned int y = 0; y < strlen(string1); y++){
    	for(unsigned int x = 0; x < strlen(string2); x++){
    		if(string1[y] == string2[x]){
    return 0;
    only 'f' an 'a' from string1 exitst in string2...these are all that are outputted.....

    Oh... I used char arrays, but the principle applies to other arrays too
    Last edited by Fordy; 11-22-2001 at 02:00 PM.

  3. #3


    Thank you so very very much, i really appreciate this, i've been tormented with this one for months (bit of a newie)
    thanks! rocks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing Arrays question
    By taugust7 in forum C++ Programming
    Replies: 36
    Last Post: 04-14-2009, 12:29 PM
  2. Comparing elements of character pointer arrays
    By axe in forum C Programming
    Replies: 2
    Last Post: 11-14-2007, 12:20 AM
  3. Comparing 2 elements from 2 different arrays
    By Dan17 in forum C Programming
    Replies: 3
    Last Post: 11-15-2006, 02:43 PM
  4. comparing arrays
    By dustyrain84 in forum C Programming
    Replies: 1
    Last Post: 01-21-2004, 05:52 PM
  5. comparing character arrays
    By Neildadon in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2003, 05:29 AM