Few questions about C syntax

后端 未结 8 799
暖寄归人
暖寄归人 2021-01-24 02:58

I have a few questions about C syntax.

  1. ch = (char *) malloc( sizeof( char ) * strlen(src) ); What do the first brackets mean (char *) ?

8条回答
  •  长情又很酷
    2021-01-24 03:32

    I d like to add to @Alok Save s answer. He has analysed it correctly however, another simple solution exists for that case and that is to use scanf with a whitespace in the string format as follows:

    scanf(" %c", &variable);
    

    This is because %c does not absorb the newline character like others(like %d) do. Any whitespace in the format string will cause scan to absorb all consecutive whitespaces thereby obviating the need for another scanf statement.

    Hope this helps!

提交回复
热议问题