#Im a beginner in C and im having a trivial problem

45 messages · Page 1 of 1 (latest)

languid granite
#

this is the code I write, and i get the output "Hello worldAge is 18".
How can i make it print the second printf in a newline instead of the same line??

onyx auroraBOT
#

Hi there! Welcome to the forum. It looks like you're having a problem with C, which is great! To help you get the best answers, could you please provide more details about your issue? For example:

  • What specific problem are you encountering?
  • What code have you written so far?
  • What error messages are you seeing (if any)?

Providing this information will help others understand your problem and offer more relevant solutions. Thanks!

languid granite
onyx auroraBOT
# languid granite 1. its not printing in new line 2. ``` #include<stdio.h> int main() { int ...

It looks like you're having trouble with your C code's output. The \n character is the newline character in C. It tells the program to move the cursor to the next line. Your code is already correct!

Here's the code you provided:

#include <stdio.h>

int main() {
    int age = 18;
    printf("Hello world \n");
    printf("Age is %d \n", age);
    return 0;
}

This code will print:

Hello world
Age is 18

If you're still having trouble, double-check your compiler and environment to make sure everything is set up correctly. If you have any other questions, feel free to ask!

mellow temple
#

1sec

languid granite
mellow temple
#

i'm not sure, it did print on a new line for me 🤔 What editor are you using?

languid granite
#

did i not install C the right way or something?

silver ravine
onyx auroraBOT
silver ravine
languid granite
#

is that good enough?

silver ravine
#

Uhhhhh I don't know how to use vs code

#

And I don't recommend using it to run your code

mellow temple
#

also on vscode

#

if you are on windows maybe doing \r before the n?

printf("Hello world\r\n");
printf("Age is %d\r\n", age);
languid granite
silver ravine
#

You should learn to compile and run your c code yourself and not rely on vscode doing it for you

languid granite
#

hey i know how to use gcc filename

#

and ./a.exe

silver ravine
#

Try use it then

languid granite
#

but its just convenience reasons

silver ravine
#

Save your file and recompile

languid granite
#

ill try

silver ravine
#

That's my gut instinct when you encounter a trivial issue like that lol

languid granite
#

YOOOOO

#

IT WORKED

mellow temple
#

the recompile?

languid granite
#

Wait so the extension i installed is the problem?

languid granite
#

but why is extension giving problems?

#

how can i fix it

#

wait wtf

#

its working well with that too

#

maybe i didnt save it and thats why its giving the problem?

languid granite
#

well

#

first lesson of C ig

#

thanks yall

mellow temple
#

🔥

silver ravine
#

You gotta save and recompile whenever you want to run your code

#

Otherwise it'll always be an older one

patent minnow