top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a C program which accept two strings and print characters in second string which are not present in first string?

+2 votes
847 views

Write a C program which accept two strings and print characters in second string which are not present in first string?

Example:
String 1: apple
String 2: aeroplane

output:
ron

posted Oct 26, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

I wrote a program which is giving the expected outcome.

#include<stdio.h>

int main(int argc, char *argv[])
{
   char *str1 = argv[1]; /*"apple";*/
   char *str2 = argv[2]; /*"aeroplane";*/
   int bitMask = 0;

   while (*str1 != '\0')
   {
      bitMask = bitMask | (1<< (*str1 - 'a'));
      str1++;
   }

   while (*str2 != '\0')
   {
      if (!(bitMask & (1<<(*str2 - 'a'))))
      printf("%c", *str2);
      str2++;
   }

   return(0);
}

Here, bitMask is an integer 32 bit long variable.

answer Oct 26, 2015 by Vikram Singh
Similar Questions
0 votes

Enter character: r
Enter string: programming
Output: Positions of 'r' in programming are: 2 5
Character 'r' occurred for 2 times

+2 votes

Given a string and two words which are present in the string, find the minimum distance between the words

Example:
"the brown quick frog quick the", "the" "quick"
Min Distance: 1

"the quick the brown quick brown the frog", "the" "brown"
Min Distance: 2

C/Java code would be helpful?

–1 vote

Write a C program to check if the given string is repeated substring or not.
ex
1: abcabcabc - yes (as abc is repeated.)
2: abcdabababababab - no

+2 votes

Input:
arr = {'a', 'b'}, length = 3

Output:
aaa
aab
aba
abb
baa
bab
bba
bbb

...