hi,I'm currently working on a program in C++.I have a string for ex
"Hello
Hai
How are you"

When i print it using outtext im not able to get the output same as that of the string, the new line character"\n" is replaced by some other special charecter,and is printed as a continuous text.Is there any way to solve this.I've to do this using outtext command only.Plz reply.Thanks in advance

The new line char won't print to the screen if that's what you are trying to do. If there is a wierd char showing up where the newline char should be then there is probably something wrong with either outtext or with the protocol obtaining the text to output. Without code I can't say much more than that.

//Outtext problem

#include <graphics.h>
# include<time.h>
# include<string.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;

   initgraph(&gdriver, &gmode, "");

   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }


             char a[100];
             printf("Enter Name\n");
             gets(a);
             strcat(a,"\n");
             strcat(a,"how");

         strcat(a,"\n");
             strcat(a,"r u");

   outtextxy(100,100,a);
   getch();
   closegraph();
   return 0;
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

Comments
>10 posts and still posting without code tags - loser

Learn to use code tags to preserve indentation when posting code to the board.

This is C code, posted on the C++ board, meaning that you aren't as likely to get an answer.

This code uses an output funtion outtextxy(), not outtext(), to print to the screen. The output function is apparently from the graphics library included in the program, which is not straightforward C style output using printf(), or similar functions straight up, which is another factor limiting the number of viewers comfortable answering your question. I am not familiar with graphics.h or outtextxy() and therefore can't help you more than I have (if I have helped at all).

This article has been dead for over six months. Start a new discussion instead.