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

Recommended Answers

All 6 Replies

Are you trying to print to the screen or to a file? Post the code for outtext.

printing to a screen

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;
}
commented: >10 posts and still posting without code tags - loser -3

Is there any way to solve this?!!!!!!!!!!111

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.