Question Name:Keywords

#include <stdio.h>
#include <string.h>
struct aviraj
{ 
  char c[50];
}s1[20];
int main()
{
int i ,l,count=0;
 char  temp[10];
  for(i=0;i<10;i++) { 
    scanf("%s",s1[i].c);
  } 
  scanf("%s",temp) ;
 // printf("Keyword is %s\n",temp);
    for(i=0;i<10;i++) { 
if(strcmp(s1[i].c,temp)==0)
{count++;l=i;
 
}
    } 
  if(count>0) {   printf("Keyword is %s\n",temp);

      printf("position is %d",l+1);} 
  else { 
    printf("Keyword not found");
  } 

	return 0;
}

Problem Description

Teacher is having a list of 10 keywords in C language present in a file. The students has to find a particular keywords along with its position for an ordered list.

  • Test Case 1

    Input (stdin)

    for
    while
    if 
    int
    float
    double
    char
    struct
    include
    break
    
    char
    

    Expected Output

    Keyword is char
    position is 7
  • Test Case 2

    Input (stdin)

    for
    while
    if 
    int
    float
    double
    char
    struct
    include
    break
    
    switch
    

    Expected Output

    Keyword not found
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock