Home > Software engineering >  How can I add a line break after a variable in C?
How can I add a line break after a variable in C?

Time:11-27

I am new to C and I am learning how to add a line break. Although it's easy, I haven't been able to figure out how to do it after a variable, taking into account that it's at the end of the line.

This is the code with the error, as you can see, I added '\n' after varA and varB

#include <stdio.h>

int main(void)
{
    char  varA = 10;
    int   varB = 150;
    float varC = 1.25;
    
    printf("The value of varA is: %d", varA, '\n\');
    printf("The value of varB is: %d", varB, '\n');
    printf("The value of varC is: %.3f", varC);
    return 0;
}

CodePudding user response:

Here is the answer:

#include <stdio.h>

int main(void)
{
    char  varA = 10;
    int   varB = 150;
    float varC = 1.25;

    printf("The value of varA is: %d\n", varA);
    printf("The value of varB is: %d\n", varB);
    printf("The value of varC is: %.3f\n", varC);
    return 0;
}

CodePudding user response:

This is not python, C doesn't work that way.
try something like

printf("The value of varA is: %d \n", varA);
  •  Tags:  
  • c
  • Related