Difference between \n and \r?

前端 未结 10 781
予麋鹿
予麋鹿 2020-11-21 11:17

What’s the difference between \\n (newline) and \\r (carriage return)?

In particular, are there any practical differences between

10条回答
  •  星月不相逢
    2020-11-21 11:50

    #include 
    
    void main()
    {
      int countch=0;
      int countwd=1;
    
      printf("Enter your sentence in lowercase: ");
      char ch='a';
      while(ch!='\r')
      {
        ch=getche();
        if(ch==' ')
          countwd++;
        else
          countch++;
      }
    
      printf("\n Words = ",countwd);
    
      printf("Characters = ",countch-1);
    
      getch();
    
    }
    

    lets take this example try putting \n in place of \r it will not work and try to guess why?

提交回复
热议问题