u8sand 68 Junior Poster

I don't expect febonacci numbers to be negative, so why not use unsigned, it will give you twice the amount you can go.
And %d calls an integer, not a long (so it will only show what an integer would show if it was at that value)
I would also recomend using int main() instead of void main().

Salem commented: It's not a recommendation, it's the law! +36
u8sand 68 Junior Poster

The atoi function returns an integer from a string. So:

char buf[256];
// Ask for input here
cin.getline(buf,256);
int num = atoi(buf);
if(num == 0) // atoi returns 0 if it is invalid
    cout << "Error";

Which is why you retrieve the input with a string (because a string can handle any text input) and turn it into an integer if its valid.

u8sand 68 Junior Poster

The atoi function returns an integer from a string. So:

char buf[256];
// Ask for input here
cin.getline(buf,256);
int num = atoi(buf);
if(num == 0)
    cout << "Error";
Thmyris commented: Helped so much ! Thank you ! +0
u8sand 68 Junior Poster

O Sorry, it don't let me edit now -.-
Here:

int **array;
int sizeX,sizeY;
sizeX = 5; // set to whatever
sizeY = 5; // set to whatever
array = new int*[sizeY];
for(int i = 0; i < sizeY; i++)
    array[i] = new int[sizeX];
 
// Then to delete:
for(int i = 0; i < sizeY; i++)
    delete [] array[i];
delete [] array;
u8sand 68 Junior Poster

I would recommend:

int **array;
int sizeX,sizeY;
sizeX = 5; // set to whatever
sizeY = 5; // set to whatever
array = new int*[sizeY];
for(int i = 0; i < sizeY; i++)
    array[i] = new int[sizeX];

// Then to delete:
for(int i = 0; i < sizeY; i++)
    delete array[i];
delete [] array; // i think you need the [] here but not sure.

---------------------
This is what i used in something i made, but remade it here in 5 mins. No guarantee it works -.- Even though it should...

u8sand 68 Junior Poster

I once tried to do something like this with ONLY C++. Tried to take all the contents of a document and remake it with the same thing. The problem is though that there are some characters that may not show up (may not follow ascii char set) and their may be text that is not being retrieved. Make sure your getting all the text, so use a pointer:

#include <iostream>
#include <fstream>

using namespace std;

char* main(char* file)
{
    char* contents;
    char* buffer;
    int numOfChars = 0;
    char ch;
    ifstream fin(file);
    if(fin)
    {
        while(fin.get(ch))
        {
            buffer = new char[numOfChars+2];
            for(int i = 0; i < numOfChars; i++)
                buffer[i] = contents[i];
            buffer[numOfChars] = ch;
            buffer[numOfChars+1] = '\0';
            delete contents;
            contents = new char[++numOfChars+1];
            for(int i = 0; i < numOfchars; i++)
                contents[i] = buffer[i];
            contents[numOfChars] = '\0';
            delete buffer;
        }
        fin.close();
    }
    else
        return "Error";
    return contents;
}
u8sand 68 Junior Poster

You won't be reinventing the wheel if your using dlls from other software to make it. It will just basically be organizing and making your own GUI. If you really want to "Reinvent the Wheel" then make EVERYTHING yourself.
But it will be pretty hard to use the dlls unless you have a lib.

u8sand 68 Junior Poster

Ask the person you got the source from what compiler they used, then get that compiler and use it to compiler. OR look through the errors, try and fix them. For example: In Visual Studio you write:

sprintf_s();

but in dev C++ that will return an error. It must be replaced with

sprintf();

also that cpp file doesn't help us at all because it has a ton of includes that are not included. Most of the errors are probably in those includes.

I looked through the errors and it looks like it was originally compiled on visual studio.

u8sand 68 Junior Poster

I remember looking all over for something like that but i don't think it exists... Not to worry! All windows operating systems from VISTA and above have the .NET framework already installed on it... Of course XP and lower don't -.-

I also know of a way (only with MFC though) to link the libraries in a different way so that you can run it on different systems... static linking i think? But MFC is old and never used/updated anymore.

u8sand 68 Junior Poster

because find was never defined it was defined inside a class you gotta make an object from that class and call it from the object.

AKA

search s;
s.find(unsigned mycstring, lett);
u8sand 68 Junior Poster

The only problem with Visual 2008's compiled files is that you cannot run it on other machines without the .NET framework. I recommend finding a way to get it to work without the .NET framework or get DevC++.

u8sand 68 Junior Poster

Hi again,first i must say that i am familiar with c++ but only console programming. I am beginner so can you please be more gentle. I want to move on programming with buttons,windows,check boxs,input box and so on,i have heard of API and GUI what is the diference ? They are used for ? And when i try to compile some code Qt 4 code with DevC++ it gives me a lot of error,can you tell me why i get that error,do i need new compiler or there are missing compiler libraries ? Thanks for your help and lost time with my problem :)

I honestly prefer basic console programming, you don't have to worry about registering windows classes and checking 18billion errors. If your going to use windows GUI then get a Microsoft compiler (VC++ 2008 Express Edition for example). You can't compile the code in DevC++ because Dev does not have all the library's that compilers like Microsoft compilers use. That is also why .exe's compiled with Dev are usable on any system while compiled with Microsoft's compiler the computer needs to have the .net framework.

In my point of view, Windows programming is pointless for most things, but if you move to it: Program a console app then import the class to Dev, it will make things simpler.

u8sand 68 Junior Poster

Size randomly? Then it would be completely different, you would probably use a pointer.

u8sand 68 Junior Poster

Example 1:

#include <iostream>
using namespace std;
int main()
{
int ar[10],a;
for(a=0;a<10;a++)
{
ar[a]=(rand()%45)+1;
cout<<ar[a]<<"\n";
}
cin>>a;
return 0;
}

First of all, the assignment was to create an array, never said to display it. But besides that why did you do cin >> a; at the end of the loop ? If that is waiting for you to press enter why not just use cin.ignore(); But overall, i think you did this one right, what is the problem...? Why did you post. For us to check?

u8sand 68 Junior Poster

Well i would start by learning how to make objects on the screen. Then make a Square class, Circle class, and Triangle class. And have functions that allow them to move, and get their position. Then make a loop that goes like:

// 1 = up, 2 = down, 3 = left, 4 = right
int MoveAway(int x1,int y1,int x2,int y2);
Circle c;
Square s;
Triangle t;
while(!quit)
{
    if(MoveAway(c.X,c.Y,s.X,s.Y) == 1)
        c.MoveUp();
    if(MoveAway(c.X,c.Y,s.X,s.Y) == 2)
        c.MoveDown();
    if(MoveAway(c.X,c.Y,s.X,s.Y) == 3)
        c.MoveLeft();
    if(MoveAway(c.X,c.Y,s.X,s.Y) == 4)
        c.MoveRight();
}

This would do nothing but just to give you an idea.

u8sand 68 Junior Poster
int main()
{
    char input[256];
    cout << "Insert name: ";
    cin.getline(input,256);
    cout << "\nYou name is " << (int)strlen(input) << " characters long.\n";
    cin.ignore();
    return 0;
}
u8sand 68 Junior Poster

i also edited some other problems, the one on my post is complete fixing a bunch of problems u had, also try next time you program, not to use goto's, figure out a way around them. : )

u8sand 68 Junior Poster

this program is just messing around with file i/o, and then i stumbled across something that i¨ve clearly forgot or missed in the tutorials i've read. my 'guess' is its the to if statements messing up (or perhaps rather their else's)
i know i used goto and that means i am a moron so comments about that are welcomme too (as for anything else i may have done in wierd ways:P )

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ofstream ud;
    ud.open ("C:\\Documents and Settings\\Happy\\Skrivebord\\testfile.txt", ios::app);
    if (ud.is_open())
    {
        cout << "\nur screwed, the file cant close, shutdown anyway? y/n \n";
        string shutdownyn,y="y", Y="Y", n="n", N="N";
        cin >> shutdownyn;
        if (shutdownyn==y || shutdownyn==Y)
        {
            goto faseout;
        }
        else
        {
            goto crashstart;
        }
    } // MISSED CLOSE } ON THE IF
    else
    {
        goto faseout;
    }
    //} // ?

    crashstart:
    string userin;
    cout<< "\ninput for file\n";
    cin >> userin;
    ud << userin;

    faseout:
    ud.close();
    cout << "\nprogram terminated\n";
    cin.get();
    return 0;
}

lol dumb error np : /

eh if u dident notice i changed it in the quote ^^

also a few errors..
you are adding stuff to the file before u checked if it was open.
and you closed it and then checked if it was open... duh?

u8sand 68 Junior Poster

dono what this does really but who knows its worth a try

if(tfgame.ToggleWarhead == True)
			        {
			            SMNameArray[6] = "Warhead (3000/180)";
			            SMIndexArray[6] = 7;
                                    SMArraySize=7;
			        }

maybe replace True with true?

just to be safe just make it:

if(tfgame.ToggleWarhead)
			        {
			            SMNameArray[6] = "Warhead (3000/180)";
			            SMIndexArray[6] = 7;
                                    SMArraySize=7;
			        }

maybe that works?

ddanbe commented: Nice! True is not always true. +3
u8sand 68 Junior Poster

You can use SetCursorPos() to control the position of the cursor. It returns true is it succeeds and false if not. It takes 2 arguments int x and int y. You can use GetCursorPos() to retrieve the position of cursor. it returns the same as Set...() it takes one paramater a pointer to a structure of type POINT, which contains to values long x and long y. Also if you want to send Mouse clicks then you will need to look into the function SendInput() its well documented on msdn but feel free to ask for more information.

Chris

As chris said, i used that, and enhanced your program

hope it works:

#include <windows.h>
#include <iostream>
#include <cstdlib>
void MoveMouse(int x,int y);
using namespace std;

int main(){
	bool boo = true;
	bool r = false;
	int x = 0;
	int y = 0;
	while(boo){
		if(GetKeyState(VK_LEFT)<0){
			x--;
		    if(x < 0){
				x = 0;
			}
			r = true;
			MoveMouse(x,y);
		}
		if(GetKeyState(VK_RIGHT)<0){
			x++;
			if(x < 0){
				x = 0;
			}
			r = true;
			MoveMouse(x,y);
		}
		if(GetKeyState(VK_UP)<0){
			y--;
			if(y < 0){
				y = 0;
			}
			r = true;
			MoveMouse(x,y);
		}
		if(GetKeyState(VK_DOWN)<0){
			y++;
			if(y < 0){
				y = 0;
			}
			r = true;
			MoveMouse(x,y);
		}
		if(GetKeyState(VK_SPACE)<0){
			boo = false;
			}
		if(r)
		{
    		    system("cls");
    		    cout << x << endl;
    		    cout << y << endl;
    		    r = false;
                                }
	}
	system("cls");
}

void MoveMouse(int x, int y){
	int buffer;
	for(buffer = 0; x >= buffer && y >= buffer; buffer++){
	    SetCursorPos(x,y);
	    //Sleep(1);
	}
}

Also …

u8sand 68 Junior Poster
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int main() 
{

string LogicMolecule;
string ExecutableCodeName;
int size;
vector<string> LogicMolecules;
	
cout << "Execute: ";
cin >> ExecutableCodeName;
cin.ignore(); // wana ignore the enter press here        < -------------------------------------
system("cls");

ExecutableCodeName = ExecutableCodeName + ".code";
    
ifstream ExecutableCodeFile;
ExecutableCodeFile.open(ExecutableCodeName.c_str());
	
if (!ExecutableCodeFile.is_open()) 
{
cout << "error: can't open executable code";
cout << "\n";
system("PAUSE");
}
	
while (ExecutableCodeFile >> LogicMolecule) 
{
	LogicMolecules.push_back(0);
}

ExecutableCodeFile.close();
size = LogicMolecules.size();
cout << size;
cout << "\n";
system("PAUSE");

}

used to have that problem allot. After you call
cin >> ...;
it doesent keep the '\n' you entered
so you have to ignore that, or that gets taken down and screws up everything else : )

Hope it works..


BTW it wasnt solved so thoght i could still help : /
but i guess they answerd it for you alrdy.

u8sand 68 Junior Poster

do you want all the numbers together? or only 1 at a time and get it into an array...
Here's what i did
get it as a string

char line[2500];
ifstream num("num.txt");
num.getline(line,2500); // get the line
num.close();
int array[2500];
for(int i = 0; i < (int)strlen(line); i++)
    array[i] = (int)line[i]-48; // -48 because '0' = 48, '1' = 49, it gives normal int...