ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
write the function. if all the character in string B appear in
string A, return true, otherwise return false.
 Question Submitted By :: PK
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 1
#include<iostream.h>
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100],str2[100];
int flag1=0,flag=0;
cout<<"\n\nenter 1st string:";
cin>>str1;
cout<<"\n\nenter 2nd string:";
cin>>str2;
int i=0,j=0;
for(i=0;i<strlen(str1);i++)
{ flag=0;
for(j=0;j<strlen(str2);j++)
{
if(str1[i]==str2[j])
{flag=1;
str2[j]=' ';
break;
}
}
if(flag==0)
{
flag1=1;
cout<<"\n\nnot anagrams";
break;
}
}
if(flag1!=1)
cout<<"\nanagrams";


return 0;

 }


 
Is This Answer Correct ?    0 Yes 0 No
Raghuram
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 2
#include<iostream.h>
#include<string.h>
int h(char letter)
{

return(letter-97);
}

int main()

{

char str1[100],str2[100];

int i=0,count[26];
for(i=0;i<26;i++)

count[i]=0;

clrscr();
cout<<"\n\nenter 1st string:";

cin>>str1;

cout<<"\n\nenter 2nd string:";

cin>>str2;
for(i=0;i<strlen(str1);i++)

{

count[h(str1[i])]++;

}
for(i=0;i<strlen(str2);i++)

{

count[h(str2[i])]--;
}      int flag=0;

for(i=0;i<26;i++)

{if(count[i]!=0)
{cout<<"\n\nnot anagrams";

flag=1;

break;

}
}

if(flag==0)

cout<<"\n\nanagrams";

return 0;

}
 
Is This Answer Correct ?    0 Yes 0 No
Raghuram.A
 
 
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 3
#include<iostream.h>
void main()
{
char a,b;
cout<<"Entr the values of a & b";
cin>>a>>b;
if(strcmp(a,b))
cout<<"Both a & b are the same";
else
cout<<"A & b are different";
}
 
Is This Answer Correct ?    1 Yes 1 No
Defcon
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 4
private bool IsPartOf(string B, string A)
        {
            if(A==null || B==null) return false;
            if(B.Length>A.Length) return false;
            A = A.ToLower();
            B = B.ToUpper();

            for(int i=0; i<A.Length;i++)
            {
                if((i<B.Length)&&(A[i]==B[i]))
                {
                    bool found = true;
                    for(int j=i;j<B.Length;j++)
                    {
                        if(A[j]!=B[j])
                        {
                            found = false;
                            break;
                        }
                    }
                    if(found) return true;
                }
            }
            return false;
        }
 
Is This Answer Correct ?    1 Yes 0 No
Sam
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 5
using namespace std;
#include<iostream>
#include<conio.h>
#include<string.h>

int main()
{
char str1[10],str2[10],temp[10];
char *p,*q;
int flag=1;

cout<<"enter the two strings"<<endl;
cin>>str1;
cout<<"and"<<endl;
cin>>str2;

p=str1;

//strcpy(str2,temp);
//cout<<temp;
if(strlen(str1)!=strlen(str2))
flag=0;

while(*p)
{
char ch=*p;
q=str2;
while(*q)
{
         if(ch!=*q)
         q++;
         else
         {
             *q='*';
              break;
         } 
}
if((*q)=='\0')
{flag=0;
 break;
}
p++;

}

if(flag)
cout<<"anagrams"<<endl;
else
cout<<"not anagrams"<<endl;

getch();
return 0;
}
 
Is This Answer Correct ?    0 Yes 0 No
Tushar
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 6
#include<stdio.h>
#include<string.h>

int main()
{
        char *str1 = "Hello";
        char *str2 = "Hello";

        int len1,len2;
        len1 = strlen(str1);
        len2 = strlen(str2);
        if(len1 != len2)
        {
                printf("\nBoth Strings are not matched");
                return 0;
        }

        while(*str1)
        {
                if(*str1 == *str2)
                {
                        *str1++;
                        *str2++;
                }
                else
                {
                        printf("\nString Not Matched\n");
                        return 0;
                }
        }
        printf("\nBoth String are EQual");
}
 
Is This Answer Correct ?    0 Yes 1 No
Kathiresan
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 7
why u all waisting time... First understand problem then solve. 
Problem is like that

suppose B  = "iwantto"
        A = "Hiwannachatoopsthatiswhy"

Now here all character of B is in A string...

Okay!!!
 
Is This Answer Correct ?    1 Yes 0 No
Latter
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 8
//assuming both the strings in same case
 
int main()
{
	
	string A;
	string B;
	
	int count = 0;
	char repeatChar='$';
		
	cout<<"Enter string A";
	cin>>A;
	cout<<"Enter the string B";
	cin>>B;

	if(A.length()<B.length())
	{
		cout<<"Length of string A is small than B, so all the charaters of the B can't be there in A";
		exit(0);
	}
	
	
	int A_length = A.length();
	int B_length = B.length();
	
	for(int i=0; i<B_length; i++)
	{
		for(int j=0; j<A_length; j++)
		{
			if(A[j] == B[i])
			{
				if(repeatChar == A[j])
					;
				else
				{
					count++;
					repeatChar = A[j];
					break;
				}
				
			}
		}
	}	
		
	if(count==B_length)
		cout<<"string A has all the chars of string B";
	else
		cout<<"string A doesn't have all chars of string B";
        
        return 0;
	
}
 
Is This Answer Correct ?    1 Yes 0 No
Satish Nerlekar
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 9
char B_str[] = "aaaaaa";
char A_str[] = "a"
// For the above case, this function should return true

char B_str[] = "aB";
char A_str[] = "aaaaaBaaaaaa"
// For the above case, this function should return true

int B_chars[256]; //for all unique chars in B_str

/* Init B_chars[] */
for( int i = 0; i < 256; i++ )
    B_chars[i] = 0;

/* Get characters in B_str */
for( int i = 0; i < strlen(B_str); i++ )
    B_chars[(int) B_str[i]]++;

/* check if A_str has which of them */
for( int i = 0; i < strlen(A_str); i++ )
    B_chars[(int) A_str[i]] = 0;

/* If any of the B_chars[] has non-zero entry */
for( int i = 0; i < 256; i++ )
{
    if( B_chars[i] != 0 )
    {
       return (false);
    }
}

/* Otherwise return true   */
return (true);
 
Is This Answer Correct ?    0 Yes 0 No
Somisetty
 
  Re: write the function. if all the character in string B appear in string A, return true, otherwise return false.
Answer
# 10
//This works for strings of a fixed length(here 10)..Its
written in assumption that strings are given in same case
completely(ie,india,INdia will be false witout modifican..

#include<stdio.h>
#include<string.h>
main(){
  char a1[10],a2[10],cn[10]={0,0,0,0,0,0,0,0,0,0};
  int i,j,k,l,c=0;
  printf("enter string B\n");
  scanf("%s",a1);
  printf("enter string A\n");
  scanf("%s",a2);
 for(i=0;i<strlen(a1);i++){
        for(j=0;j<strlen(a2);j++){
           if(a1[i]==a2[j]){
           c++;
           cn[i]=1;
           }}}
           for(k=0;k<strlen(a1);k++){
           if(cn[k]==0){
           printf("FALSE\n");exit(0);}}
           printf("TRUE\n");}
 
Is This Answer Correct ?    5 Yes 0 No
Patrick
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }  1
main() { int i = 3; for (;i++=0;) printf(“%d”,i); }  1
void main() { int i=5; printf("%d",i++ + ++i); }  1
Give a oneline C expression to test whether a number is a power of 2? Motorola16
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }  1
main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }  1
main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error HCL1
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }  1
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }  1
write a program in c to merge two array  1
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }  1
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }  1
main() { int i=400,j=300; printf("%d..%d"); }  1
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. Synergy2
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }  1
#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }  1
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);  1
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. Microsoft15
plz send me all data structure related programs  2
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com