Find the specified character

#include <stdio.h>

#define N 80

int main ()

    char a,ch,str[N];

    int len ​​= 0, i;

    flag = -1 int;                 // array index starts from 0, by determining whether flag = -1 to find the specified character.

    scanf("%c\n",&a);

    getchar = ch ();             // char ch; ch = getchar () means the variable ch is defined as char character type, when the keyboard input of a character, the value assigned to the variable ch.

                                          Action getchar () function from the computer terminal (typically a keyboard) to enter a character. getchar () function can only receive a character, the character is a function of the value obtained from the input device.

                                            When the program calls getchar, program waiting for user keys. Characters input by the user is stored in the keyboard buffer, up until the user presses Enter (carriage return character is also put into the buffer).

    for (i=0;ch!='\n';i++)

    {

          str[i]=ch;

          as ++;

          ch=getchar();

    }

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

     {

         if (a==str[i])

         flag=i;

      }

      if (flag!=-1)

      printf("index = %d\n",flag);

      else

      printf("NOT FOUND");

      return 0;

}

      

         

          

Guess you like

Origin www.cnblogs.com/DEAKY/p/11922734.html