What is the symbol for whitespace in C?

后端 未结 7 2109
醉话见心
醉话见心 2020-12-13 08:50

I am trying to figure out how to check if a character is equal to white-space in C. I know that tabs are \'\\t\' and newlines are \'\\n\', but I wa

7条回答
  •  半阙折子戏
    2020-12-13 09:35

    #include 
    main()
    {
    int c,sp,tb,nl;
    sp = 0;
    tb = 0;
    nl = 0;
    while((c = getchar()) != EOF)
    {
       switch( c )
    {
       case ' ':
            ++sp;
         printf("space:%d\n", sp);
         break;
       case  '\t':
            ++tb;
         printf("tab:%d\n", tb);
         break;
       case '\n':
            ++nl;
         printf("new line:%d\n", nl);
         break;
      }
     }
    }
    

提交回复
热议问题