Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why newline character isn't printed. #2778

Open
DuilioPerez opened this issue May 18, 2024 · 0 comments
Open

Why newline character isn't printed. #2778

DuilioPerez opened this issue May 18, 2024 · 0 comments
Labels
userquestion not quite bugs--inquiries from users

Comments

@DuilioPerez
Copy link

I'm learning to use notcurses by my own way. I've created a program to transcribe DNA into RNA. Here is the code

#include <notcurses/notcurses.h>
#include <string>
using namespace std;

bool verify(int c, string &dna)
{
  if (c == 'a' || c == 'A' || c == 'g' || c == 'G' ||
      c == 'u' || c == 'U' || c == 'c' || c == 'C' ||
      c == 't' ||
      c == 'T') // Includes 't' and 'T' in valid characters
  {
    dna += static_cast<char>(c);
    return true;
  }
  return false;
}

string rna(const string &dna)
{
  string rna;
  for (char c : dna)
  {
    if (c == 't' || c == 'T')
      rna += 'u';
    else
      rna += c;
  }
  return rna;
}

int main()
{
  string            dna;
  int               c;
  notcurses_options options = {};
  notcurses        *app = notcurses_init(&options, stdout);
  if (!app)
  {
    fprintf(stderr, "Error initializing Notcurses\n");
    return 1;
  }
  ncplane *stdplane = notcurses_stdplane(app);

  // Clear screen at start
  ncplane_erase(stdplane);
  ncplane_putstr(stdplane, "Enter the DNA code (press 'q' to quit):");
  notcurses_render(app);

  while ((c = notcurses_get_blocking(app, nullptr)) != 'q')
  {
    if (verify(c, dna))
    {
      ncplane_putchar(stdplane, static_cast<char>(c));
      notcurses_render(app);
    }
  }

  ncplane_putstr(stdplane, "\nTranscribed RNA: ");
  notcurses_render(app);
  ncplane_putstr(stdplane, rna(dna).c_str());
  notcurses_render(app);

  // Wait for user to press 'q' to exit
  while (notcurses_get_blocking(app, nullptr) != 'q')
    ;

  notcurses_stop(app);
  return 0;
}

When I add a newline to the beginning of a string, it doesn't print using ncplane_putstr, or when I do something like ncplane_putchar(stdplane, '\n') it doesn't work. I'm using Termux to program.

@DuilioPerez DuilioPerez added the userquestion not quite bugs--inquiries from users label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
userquestion not quite bugs--inquiries from users
Projects
None yet
Development

No branches or pull requests

1 participant