Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
You are given a "secret" string, and you are given a "guess"
string. Both strings have exactly 5 characters.

Assume that each letter occurs at most one time in the secret string and the
guess string.

Some of the letters in the guess string occur in the same position as
the secret string. Call the number of such letters as I.

Some other letters in the guess string occur in the secret string, but
in some other position. Call the number of such letters as J.

You have to output
I#J


What I have tried:

#include<stdio.h>
void main()
{ 
  int
  char str1[5]="secret";
  char str[5]="guess";
}
Posted
Updated 15-Apr-22 0:32am
Comments
Graeme_Grant 15-Apr-22 1:26am    
This is a pointer/index exercise, ie, walking the characters and checking for matches...

We are not here to do your homework for you. You need to write some code, not give us the exercise to do.
Subhasish Bagchi 2022 15-Apr-22 1:48am    
but it's not working
Graeme_Grant 15-Apr-22 1:51am    
there is no code in the question above. I'm sure it won't.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
jaka jaka 15-Apr-22 2:16am    
You are given a "secret" string, and you are given a "guess"
string. Both strings have exactly 5 characters.

Assume that each letter occurs at most one time in the secret string and the
guess string.

Some of the letters in the guess string occur in the same position as
the secret string. Call the number of such letters as I.

Some other letters in the guess string occur in the secret string, but
in some other position. Call the number of such letters as J.

You have to output
I#J
jaka jaka 15-Apr-22 2:23am    
You are given a "secret" string, and you are given a "guess"
string. Both strings have exactly 5 characters.

Assume that each letter occurs at most one time in the secret string and the
guess string.

Some of the letters in the guess string occur in the same position as
the secret string. Call the number of such letters as I.

Some other letters in the guess string occur in the secret string, but
in some other position. Call the number of such letters as J.
OriginalGriff 15-Apr-22 3:39am    
Yes, I got that from the original post.
But I'm not going to do your homework for you: it's your task, and me doign it would be counterproductive in the long run ...
#include<stdio.h>
#include<string.h>
int main()
{
char str1[5],str2[5],str3[5];
int i,j=0,k=0,I=0,J=0;
printf("Enter string 1 = ");
scanf("%s",&str1);
printf("Enter string 1 = ");
scanf("%s",&str2);
while(str1[i]!='\0')
{
if(str1[i] == str2[i])
I++;
else
{
str3[k] = str2[i];
//printf("%d-%c,",k,str3[k]);
k++;
}
i++;
}
//printf("k=%d\n",k);
i=0;
while(str3[i]!='\0')
{
j=0;
while(str1[j]!='\0')
{
if(str1[j] == str3[i])
J++;

j++;
}
i++;
}

printf("%d#%d",I,J);
return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900