Hello Everyone , I am writing a code in which i search a char array and look at what is missing in the array i mean what letters are missing in the array.

I worked out a small code but i seem to have some error in the answer though it compiles fine.
This is not a homework assignment. But a small project i am working on which needs something same like this.

Here is my code.

#include <iostream>
using namespace std;

int main()
{
    char one[10];
    char two[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int s;
    cout<<" Enter one word:: \n";
    cin>> one;
    for (int a=0;a<=strlen(one);a++)
    {
        for (int b=0;b<=25;b++)
        {
            if (one[a]!=two[b]){ s=a;}
            else{ 
                  break;
            }
        }
      cout<< two[s];  
    }
    cin.get();
    cin.get();
}

I'm not sure what output you are expecting. Could you post an example of what your program is supposed to do?

Well if i give in input such as "shark". I want the program to then remove the letters s,h,a,r,k from the alphabets and post in an answer such as this one

input :: "shark"
output ::b,c,d,e,f,g,i,j,l,m,n,o,p,q,t,u,w,x,y,z.

And then i wanna store that value in another array but first i was trying to print out the answer.

In that case, your loops are inside out. The outer loop should run through the alphabet and the inner loop should check every letter against your input. If the letter was found, raise somesort of flag (bool) and only display the letter if this flag wasn't set by the inner loop.

for (int a=0;a<=strlen(one);a++)

Change this to : for (int a=0;a<strlen(one);a++) or else you'll get undefined behavior because you'll go out of your array bounds.

Niek

Maybe use string erase...

#include <iostream>
#include <string>

using namespace std;

class Test
{
public:
   void getMissingletters ( string test )
   {
      string p = "abcdefghijklmnopqrstuvwxyz";
      string build = "";

      for  ( int i = 0; i < p.length(); i++ )
      {
         for ( int j = 0; j < test.length(); j++ )
         {
            if ( test[j] == p[i] )
            {
               p = p.erase(i,1);      
            }
         }
      }
      cout << p;
   }
};

int main()
{
   Test t;
   t.getMissingletters ( "shark" );

   cin.get();
}

I was trying to create a bool flag from yesterday. But was not able to come up with a solution for the problem.

I was actually doing the Encryption code problem which was posted by aminit on these forums
here is a link

http://www.daniweb.com/forums/thread117714.html

I will now post down the original code which is still unfinished and i am placing a similar problem in the code. So i decided to first get a different program to perform the function and then copy and paste the code and modify it in my original

Here is the original code

#include <iostream>
using namespace std;
         
         int s;
int main()
{         int s1,j;
          char en[26],ci[26],keyword[10],key,message[40];
          cout<<"\nEnter the keyword\n";//beta
          cin>>keyword;
          cout<<"Enter the key\n";//r
          cin >>key;
          cout<<"Enter the message that you want to cipher: \n";
          cin >> message;
          cout<<"Your keyword is:: "<<keyword<<"\n";
          cout<<"Your Key is :: "<<key<<"\n";
          cout<<"Your message is :: "<<message<<"\n";
              
          int y=0;
          for(int x='a';x<='z';x++)
          {//This creates the English Alphabets placed in en
          en[y]=x;
          y++;
          }
          
          for (int j=0;j<=25;j++)
          {
              if (key == en[j])
              {
                      ::s = j;//Getting the Cypher KEY number to continue
              }
          }
          cout<<"The cypher Key Number is "<<s<<"\n";
          

int b=0;
          for (::s;b<=strlen(keyword);s++)
          {
              ci[s]= keyword[b];
              b++;
          }
          for(b=0;b<(s-(strlen(keyword)+1));b++)
          {ci[b]='0';}
          for(b=(s-1);b<=25;b++)
          {
               ci[b]='0';
          }
          int a;
/*Here i am trying to get the function to place the remaining letters into the array on the right hand site first and the remaining on the left hand side so that i will get the total cypher code But i get no errors during compile time or runtime but the wrong answers. */
          for(a=(s-1);a<=25;a++)
          {
               for(b=0;b<=25;b++)
               {
                                 for(int c=0;c<=25;(c++))
                                 {
                                         if(en[b]!=ci[c])
                                         {
                                          s1=c;                                        
                                         }
                                         else{
                                         break;
                                         }       
                                 }                  
                                      
               }
               j=s1;
                ci[a]=en[j];
               
                
          }     
                          
                             
          for(int d=0;d<=25;d++){cout<<ci[d];}//Trying to see what its producing..
          cout<<"\n"<<en;                 
          cin.get();
          cin.get();
}
//And over here will be the remaining part of the program where i take the message and then encrypt it up using the cypher alphabets comparing to the english alphabets.

Please help me out on what i am doing wrong.

I meant something like this:

bool flag = false
loop through the alpabet
    loop through the input
       check if letter from alphabet is in the input
           flag = true
     end loop
     if flag = false
        print the letter 
     reset flag to false
end loop

But Iamthwee's code would also work

This question has already been answered. Start a new discussion instead.