a petite error.....can nyone plz?

Pages: 12
see i have a program, actually a project in which there are menus whch make u go from one page to another by means of printing & using the video memory) But after the first run of the program the cursor stops displaying and the statements such as gets(string) cease to show any characters on the screen??????? i wish to know what could be causing this..........Your help or comments would be greatly appreciated..................... :)
[code]#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

main()
{
FILE *ptr; char a[12];
int i,j;
for(i=2;i<=49;i++)
{
for(j=2;j<=79;j++)
{gotoxy(j,i);
cprintf(i,j,' ',0);
}
}

ptr=fopen("C:\\new.txt","w");
fprintf(ptr,"hello");
getch();
textattr(18);
gotoxy(10,10);
cprintf("Hello");
gets(a);
getch();
puts(a);
getch();
}

Last edited on
closed account (S6k9GNh0)
This shouldn't even compile.

1. The main entry function is declared as "int main()".
2. Do not use conio.h, it's dated, buggy, and has better alternatives.
3. This is C, not C++ which means this is the wrong forum in general (although someone may still answer you).
4. What the f$#k is going on line 32?
Good God, is that the VGA memory address I see you try to write to?
I don't think your write2screen() function will work on anything more recent than Win3.1 on 16 bits.
well i am sorry for mentioning it i havent used the function write2screen //in this sectionwell its just unneccessary for this part of my program.......................just run it more than once consecutively on ur Compiler and ullnotice that the second time we see no cursor
plz reach back thanks...
sumone plz figure this out!!!!
@computerquip were have i used int main()?
You used main() instead of int main().
You did not put a return 0; at the end of main().
My previous comment was dumb... but the fact remains that you're trying to write directly to VGA memory by using the write2screen() function in the for() at line 14.

Are you using DOS, with Borland C or DJGPP? Because most people nowadays don't.
If the problem is how you use the functions in conio.h, I doubt anyone here can help you.
It looks to me like you are trying to teach yourself C++ with a roughly 20 years old book.
I would recommend to move on to some newer compiler. All these conio.h, dos.h should just be left behind. There are a lot of free of charge compilers that you can choose. Why stick with those ones.

I cannot really help you on your program. You are using some non standard commands so you are on your own.

Also as a final advice if you want to learn c/c++ don't try this console color effects, getch() etc. Use some upto date commands and you will get your help.
i have made the code shorter....can neone help please..?
1
2
3
4
5
6
7
FILE *ptr; char a[12];
int i,j;
for(i=2;i<=49;i++)
{
for(j=2;j<=79;j++)
{gotoxy(j,i);
cprintf(i,j,' ',0);


What exactly is this part of the file supposed to be doing?

1
2
3
4
gets(a);
getch();
puts(a);
getch();


Why is this here?

I think you should listen to the posts above and get a free, up to date compiler such as http://gcc.gnu.org/

And then go through some newer tutorials like this one: http://www.cprogramming.com/tutorial/c/lesson1.html

closed account (S6k9GNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//#include<dos.h>
//#include<conio.h>
//#include<stdio.h>
//#include<stdlib.h>
#include <iostream> //Basic Console IO
#include <fstream> //File IO
#include <ncurses.h> //Console Manipulation

//main()
int main()
{
    //char a[12];
    //int i, j; /* This is not C90. There's no reason to do this.  */
    for(int i = 2; i <= 49; i++)
    {
        for(int j = 2 ; j <= 79; j++) //What's 79?
        {
            /*  What are you wanting here?
                You used cprintf here wrongly anyways, no way for me to understand
            */
        }
    }

    std::cout << "Loading file..." << std::endl;
    std::fstream file("new.txt"); //It's probably better to give a relative path.

    if (file)
        file << "hello" << std::endl;
    else
        std::cout << "File did not initialize correctly" << std::endl;

    file.close();
    std::cout << "Finished with file..." << std::endl;

    //textattr(18); //I'm not familiar with this.
    //gotoxy(10,10);
    std::cout << "Printing with ncurses..." << std::endl;
    {
        WINDOW* console = initscr(); //Enter curses mode
        if (console == NULL)
        {
            std::cout << "Failed to initialized ncurses. Aborting..." << std::endl;
            return 1;
        }

        mvaddstr(10, 10, "hello");
        refresh(); //Submit changes.
        getch();
        endwin();
        std::cout << "Finished printing..." << std::endl;
    }
    //gets() and puts() are dangerous....
    std::cout << "Grabbing user input..." << std::endl;
    std::string tmpStr;
    //gets(a);
    std::cout << "Enter input: ";
    std::getline(std::cin, tmpStr);
    //getch(); //Are you wanting an interrupt? What's the purpose of this?
    //puts(a);
    std::cout << "User input: " << tmpStr << std::endl;
    std::cin.get();
}


1. Your previous code needs to be removed from your mind. All of your code looks like ancient C90.

2. If you're on a C++ forum, use C++, not C, and definitely not C90. I've had enough from the ioQuake3 engine already.

3. You used libraries that are deprecated. nCurses, as far as I'm aware, is currently the only maintained console manipulation library available.

4. Do not use puts() or gets(). They're considered evil for a reason: http://www.cplusplus.com/forum/beginner/9292/

I think that's it...
Last edited on
@ computerquip: Good post, if he actually reads it.
Also with those nested for()'s with hard-coded limits at the beginning, he was setting the cursor position manually on a 80x50 character screen.
closed account (S6k9GNh0)
gotoxy(j,i); just changes the cursor position. But he didn't use cprintf correctly and given the parameters passed, it didn't seem to do anything (print spaces?). I dunno.
@computerquip - printing spaces to clear a portion of the screen
clearly stating the purpose of the code is no practical use.. i just wish to bring in notice of u worthy programmers that when i run the code for the first time all happens well:
1. first we write a string "hello" to a file new
2.Then clearing the screen save the first row and the first column.
3.Then printing hello
4.Then inputing a string into a from the user
5.Then displaying the inputted string

and between steps we use getch() to control the flow of control by the user. input through keyboard

thnks tu evryone
the problem is that after running the first time , and then returning to the compiler editor(Borland) and then rerunning the output is not as expected!!!!!!!.....plz do throw siome light on this!!!! thnks
closed account (S6k9GNh0)
Borland is outdated. Don't use it.
Last edited on
Microsoft has a program called Visual Express 2010. You can download the c++ version of that program for free.
If you want something that works via command line, I recommend GNU g++. Both of these are available for free on the internet. So please please please please do not use something outdated like Borland.
closed account (S6k9GNh0)
VC++ and g++ both work from command line, both have an IDE (gcc/g++ having a ton for all platforms), both have a debugger, both are awesome. I would suggest against the use of MinGW for Windows and the use of VC++. On Linux, I'd suggest the use of the GNU set while maybe using clang as a good secondary compiler for error messages.
@computerquip ...tnx... according to u using an outdated compiler like borland on windows xp is causing the real problems???
Pages: 12