I cannot make the "putchxy" function of <conio2.h> work

Asked

Viewed 163 times

1

Hi. I started the computer science course this year and had never been able to study any programming until then, so maybe that’s why I’m having such basic mistakes.

My problem right now is with the C library, which I have to use to do the final work of my subject, which is a game.

The teacher spent some activities for us to learn to use conium, but for now the only thing I could do was to install it hahaha The first activity outside this was "2) Implement a void function that prints a letter read from the keyboard in position (x, y) using the functions of Conio.". Looking at the functions of , I thought the function "putchxy" does just that, but when putting it in my program and compiling, I think it is doing absolutely nothing, because it should print the character read and does not do that. I used arbitrary values defined within the program for x and y.

#include <stdio.h>
#include <conio2.h>
#include <conio.h>

int main ()
{
    char ch;
    int x = 5, y = 5;

    printf("Digite uma letra no teclado:\n");
    scanf(" %c", &ch);
    void putchxy (int x, int y, char ch);

    return (0);
}

Since this was my last class, I’m pretty sure I’m still doing it right. But looking at the slides passed in class, reading about the function inside the library itself, looking for similar cases here in the stack overflow, I could not find anything that indicated me any error in my code.

I tried to write in other ways, I tried to create myself another function, I tried to invert, put the numbers themselves, but beyond that no other compilation properly.

Where did I go wrong?

  • 3

    The error is in using the conio, it is considered obsolete and non-standard.

  • It is a work for a course of the first semester of the course, I think you can forgive right

  • 1

    And besides not being standard or usable on other operating systems like Mac or Linux, this makes your code not portable. Put this aside, you just set the function putchxy instead of calling her

  • But how would I do that? I tried it in some ways, but none of it worked, so I thought that might have been my mistake, but looking at the ways I found to do it, it didn’t work.

1 answer

1

I managed to find the answer, I will answer here in case someone else has the same difficulties.

There were two mistakes:

  1. I did not call the function correctly during the main, had just stated it. I had tried in other ways, but for my second mistake they didn’t work and made me believe they were wrong too.

  2. The second error was about installing the library in Code::Blocks. Although when I installed it I added the address to Linker, for some reason (maybe I forgot to press "OK" on the way out) it didn’t save it and for such reason when I was performing the function, it just informed me that it was undefined.

I don’t know if I can explain it better, but I just wanted to formally leave my problem solved here in case anyone else has that problem. Many thanks to everyone who really helped and any suggestion or comment, I gladly accept.

That was my first question on the forum.

The code was correct, it was:

#include <stdio.h>
#include <conio2.h>
#include <conio.h>

int main ()

{
char ch;
int x = 5, y = 5;

printf("Digite uma letra no teclado:\n");
scanf(" %c", &ch);
putchxy (x, y, ch);

return (0);
}

void putchxy (int x, int y, char ch);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.