Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to get the output by line by line

+5 votes
asked Sep 16, 2024 by manikanta (170 points)

2 Answers

0 votes
answered Sep 26, 2024 by Peter Minarik (101,360 points)

I'm not quite sure what you're after.

What language are you talking about?

"Get the output line by line"? What do you mean here?

OnlineGDB shows you the standard output of the program you run, so all you need to do is print things to the standard output line by line, meaning adding a new line when required.

For instance, in C/C++, you can use the newline character ('\n') to start a new line, just like in the example below.

#include <stdio.h>

int main()
{
    printf("This goes to the first line.");
    printf(" And so does this.");
    printf("\nBut now, a new line is started and a new line character is added after the sentence.\n");
    printf("So anything printed next, like this line, starts the line.\n");

    return 0;
}

If this is not what you're after, please, add more details.

0 votes
answered Oct 11, 2024 by Nikhila Nandyala (410 points)
L=["Geeks\n"," for\n,"Geeks\n]
#writing to file
file 1= open('myfile.txt','w')
file1.writelines(L)
file1.close()
#using for loop
Print("using for loop")
for line in file 1:
       count+1=1
       Print("Line{}:
{}".format(count,
line.strip()))
file1.closr()
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...