Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BASIC STRING PROGRAM You should write a program in C that has a string in it, an

ID: 3700763 • Letter: B

Question

BASIC STRING PROGRAM

You should write a program in C that has a string in it, and asks the user to guess the string.

Your program should tell the size of the string in the beginning. Pleas do not use a string containing more than 5 characters.

If the user guesses a correct character, your program should print the position of the correct character.

If the user cannot guess the correct string, your program should be terminated after 10 tries.

If the user guesses all the characters correctly, your program should show the word and be terminated.

Every thing should be in lower case.

The position your program shows starts at 1.

note: do not use malloc or alloc but you can use functions or arrays or strings

do not use struct keyword

please do not use strlen() function in string.h .

thankyou

sample output:

Example:

I have a word with the length of 4.

Try number: 1 -----------------

Guess a character in the word: p

No! Sorry about that. You can do better.

Try number: 2 ----------------

Guess a character in the word: l

Yay! You are super smart! You nailed it.

l is in position 1.

Try number: 3 ----------------

Guess a character in the word: o

Yay! You are super smart! You nailed it.

o is in position 2.

Try number: 4 ----------------

Guess a character in the word: v

Yay! You are super smart! You nailed it.

v is in position 2.

Try number: 5 ----------------

Guess a character in the word: e

Yay! You are super smart! You nailed it.

e is in position 4.

Wow!!! I cannot believe it. You just guessed the whole word:

love

Explanation / Answer

#include<stdio.h>
int main()
{
   int len,count=1,count1=0,i=0;
   printf("Enter the string length :");
   scanf("%d",&len);

   if(len>5) break;
   char ch[len],c,ch1[len];
   for(i=0;i<len;i++)
   {
       scanf("%c",&ch[i]);  
   }
   while(count<11)
   {
   printf("Try number: %d -----------------",count);
   printf("Guess a character in the word : ");
   scanf("%c",&c);
   for(i=0;i<len;i++)
   {
       if(c==ch[i])
       {
       printf("Yay! You are super smart! You nailed it.");
       printf("%c is in position %d",c,i);
       count1++;
       }
       else
       {
       printf("No! Sorry about that. You can do better.");
       }
       count++;
   }
   }
   if(count1==len)
   printf("Wow!!! I cannot believe it. You just guessed the whole word:");
   for(i=0;i<len;i++)
   {
       printf("%c",ch[i]);  
   }
}