New line in c

In C, there are a few ways to insert a new line:

  1. Using \n: You can use the \n character to insert a new line. This is a special character called a newline character. For example:

    printf("Hello\nWorld");

    This will print "Hello" followed by a new line, and then "World".

  2. Using printf with a format string: You can use the printf function with a format string that includes a newline character. For example:

    printf("Hello %s\nWorld", "there");

    This will print "Hello there" followed by a new line, and then "World".

  3. Using puts: The puts function is similar to printf, but it automatically appends a newline character to the end of the string. For example:

    puts("Hello World");

    This will print "Hello World" followed by a new line.

  4. Using fprintf: If you're writing to a file instead of the console, you can use fprintf to insert a new line. For example:

    FILE *fp = fopen("example.txt", "w");
    fprintf(fp, "Hello\nWorld");
    fclose(fp);

    This will write "Hello" followed by a new line, and then "World" to the file "example.txt".

Note that in all cases, the \n character is used to insert a new line. This is because the \n character is a special character that tells the terminal or file to move to the next line.