Issue in scanning the user input like: scanf("%[^\n]", name);

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Issue in scanning the user input like: scanf("%[^\n]", name);

      New

      I know this is an unsecure way of using scanf. When I use this in any other web/local IDE, program works.

      I'm using Segger Embedded Studio for RISCV V 5.60a 64 bit non commercial license for non embedded learning purpose

      C Source Code

      1. #include <stdio.h>
      2. #include <math.h>
      3. int main() {
      4. char name[50];
      5. printf("Enter any string: \n");
      6. scanf("%[^\n]", name);
      7. int i;
      8. for (i = 0; i <= 50; i++) {
      9. if (name[i] == '\0')
      10. break;
      11. }
      12. printf("\nThe length of the string is: %d.", i);
      13. return 0;
      14. }
      Display All