Freaky_Chris 299 Master Poster

What exactly is it you want to do with ctime. There isn't alot to it...and when you consider that ctime is justthe newest version of time.h that was written for C it's no wonder alot of the material out there is C based...because it's a C based header file.

None the less what exactly do you want to do?
http://www.cplusplus.com/reference/clibrary/ctime/
The above reference link may also help

Chris

Freaky_Chris 299 Master Poster

I agree with mosaic.

int main(void){
  system("notepade.exe");
  return 0;
}

Chris

Freaky_Chris 299 Master Poster

Um... well did you?

Freaky_Chris 299 Master Poster

^^ My above posted answered that and explained why.

If thats all mark the thread as solved

Chris

Freaky_Chris 299 Master Poster

It's because open() expects a null terminated string rather than a string class. you can do the following

read_file.open(in_file.c_str());

Chris

Freaky_Chris 299 Master Poster

You are including a header file more than once, if you are going to do this you need to use #ifndef #define #endif etc etc

Chris

Freaky_Chris 299 Master Poster
#include <iostream>
#include <windows.h>

using namespace std;

int main(void){
    bool updown = false;
    while(1){
        if(!updown){
            for(int x = 0; x < 100; x++){
                for(int y = 0; y < x; y++)
                    cout << endl;
             cout << "      .---.      "<< endl;
             cout << "     /__\\__\\     "<< endl;
             cout << ".---------------."<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "'---------------'"<< endl;
             Sleep(10);
             system("cls");
            }
            updown = !updown;
        }else{
            for(int x = 100; x > 0; x--){
                for(int y = 0; y < x; y++)
                    cout << endl;
             cout << "      .---.      "<< endl;
             cout << "     /__\__\     "<< endl;
             cout << ".---------------."<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "||      |      ||"<< endl;
             cout << "'---------------'"<< endl;
             Sleep(10);
             system("cls");
            }
            updown = !updown;
        }
    }
    return 0;
}

It's a bit broken but I'm …

Comatose commented: :) Nice +8
Freaky_Chris 299 Master Poster

http://en.wikipedia.org/wiki/Magic_square

Google has plenty more.

Chris

Freaky_Chris 299 Master Poster

Using Win32 Development it will be platform specific. IE it will only work on M$ Windows.
http://www.winprog.org/tutorial/
That is a rather nice tutorial on how to get started. You should also use MSDN for a reference manual if you are seriously looking at writing unmanaged Win32 Applications!

Chris

Freaky_Chris 299 Master Poster

Have a nice day!

Chris

StuXYZ commented: really nice use of urls / + generally good posts. +3
Freaky_Chris 299 Master Poster

Perhaps we could welcome him to the world of C++, rather than staying in the dark ages of C. Vectors, as have already been suggested would be a better approach....as would stringstreams.

#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>

using namespace std;

int main(void){
    ifstream data("test.dat", ios::in);
    string line, temp;
    istringstream oss;
    int count = 0;
    vector< vector<string> > DataFromFile;

    while(getline(data, line)){
        DataFromFile.push_back( vector<string>() );
        oss.clear();
        oss.str(line);
        while(oss >> temp)
            DataFromFile[count].push_back(temp);
        count++;
    }

    for(int i = 0; i < DataFromFile.size(); i++){
        for(int x = 0; x < DataFromFile[i].size(); x++)
            cout << DataFromFile[i][x] << '\t';
        cout << endl;
    }
    return 0;
}

Chris

Freaky_Chris 299 Master Poster

eeek indent overload.
Also what is the problem exactly...?

We cannot fix it if we do not know it!

Chris

Freaky_Chris 299 Master Poster

I think you're confusing people with the use of the word bit

Freaky_Chris 299 Master Poster

Also a starting point would be nice...so we can point out where you have gone wrong.

Chris

Freaky_Chris 299 Master Poster
Freaky_Chris 299 Master Poster

You'll have to gets started before people will help you. We don not do your work for you. Google will turn up some material andthe rest you should already know...such as the basics behind it.

Chris

Freaky_Chris 299 Master Poster

Since he doesn't seed rand at any point he is always going to get the same number back from it

Freaky_Chris 299 Master Poster

On windows the following code will move the mouse cursor.

#include <windows.h>

int main(void){
  SetCursorPos(50, 50);
  return 0;
}

Of course you will want to play around with that. If you want more detail just ask

Chris

Freaky_Chris 299 Master Poster

Next question when you downloaded and installed the Code::Blocks IDE Itrust you actually downloaded the installation that comes with MinGW?

Chris

Freaky_Chris 299 Master Poster

Or for a more reliable solution (ei for more than just ASCII) you can use tolower() and toupper() functions found in the cctype header

Chris

Freaky_Chris 299 Master Poster

By defining mathematical operations he means you need to deal with things such as addition, multiplication etc.
You would do this by overloading the different operators such as operator+().
Also the you will want to overload the stream operators as grumpier suggested that would be the << and >> so that the data can be outputted into files and the standard output. Aswell as read into your data type.

Chris

Freaky_Chris 299 Master Poster

Coming back to the original post. (sorry).

I think it is a level of depth. For Java, yes you do GUI/ graphics from a previously written library. For the c++ you are seeing a deeper part of computer programming, i.e. the lower level, the bit that builds the library. If you do more embedded stuff, you would learn assembler.

Interestingly there is a shift between the [old?] self-taught programmers who did basic (until aged 10) - assembler - C - C++ - Java, and the CS programmers who did Java-C++-C-assembler in that order. The self-taught know that the CS people don't understand pointers/memory correctly and the CS people know that the self-taught spend way to long programming something that is a one line library call, [even if it isn't exactly what was wanted].

Your course, could have done it the other way around (C++ first then java), but java hides some of the pointer stuff from you.

It is important to code at the lowest level required and no lower.
For my work, we use absolutely no java, it is 85% c++/fortran, some Schema, some Octave, but then I do numerical stuff that burn a few 1000 days of CPU per run. The graphics are C++ but so much of the rest is, it was a natural extension.

Would we use java? just for the graphics (had we not had to build the numerical engine). Yes! Could we do the numerics in java, maybe but the extra hardware to …

Freaky_Chris 299 Master Poster

I advise you use getline() for ALL data types and use string streams to convert them to int etc rather than cin.ignore()!


Chris

Freaky_Chris 299 Master Poster

> I think that when being class taught you are worse off.
Yeah, judging from all the brain-damage we see posted around these parts saying "my teacher said use this....", where some snippet of code is flat-out wrong.

I'm dreading starting my Computer Science course in september...don't wanna get into an argument with my lecturer....thankfully i'll be doing Java so I wont go skitz at him about void main() lmao

Freaky_Chris 299 Master Poster

do you fdefine your ClassName as a string or a char array?

Freaky_Chris 299 Master Poster

You could always write your own implementation....that way it would only use things avaliable to you in the STL

Chris

Freaky_Chris 299 Master Poster

I think that when being class taught you are worse off. You tend to take the information you are fed and that is enough for you, you think it is correct. However when you teach yourself from books and the internet you wonder wether the resources information is actually 100% correct. So this means you then take the time to contnue to look around the internet for other sources and seeks help from other people about each indervidual topic.

This means that you gain a much better undertsnading of how things work and more likely a much better approach to doing things. Also you will learn valuable skills of being able to work out things more on your own rather than copying from class taught material!

The Win32 API is quite nice to work with and is VERY well documented on MSDN making it reasonable easy to learn, as long as you do not let it overwhelm you to start with.

I have never used OpenGL so I cannot comment on it directly but I have had a look at DirectX 9 which doesn't make it too complicated to use graphics. The main aspect of graphics programming is all about the Math behind it. If you can get yourself a good OpenGL reference then with a bit of common sense you can implement almost anything your mathematicals skills allow.

Chris

Freaky_Chris 299 Master Poster

You cannot write this to be multi platform. As Salem said you will need to use the windows console functions to deal with things such as system("cls") however these libraries are non standard to all OS's only windows. Also you would need to use the windows.h header for effective directory operations. But since this is all windows based development it is not cross platform.

As far as I am aware there is no cross platform method (using standard libraries) that will allow you to produce something like this.

Chris

Freaky_Chris 299 Master Poster

if you want even bigger numbers then you can always make your own number data type using a string

Chris

Freaky_Chris 299 Master Poster
#include <iostream>
#include <windows.h>
#include <ctime>

using namespace std;

int main(void){
    int hours = 36;
    int mins = 57;
    int secs = 58;
    while(1){
        system("cls");
        if(hours > 0 || mins > 0 || secs > 0){
            cout << "Deadline in: " << hours << "h" << mins << "m" << secs << "s";
            if(mins == 0){
                if(hours != 0){
                    mins = 59;
                    hours -= 1;
                }
            }
            if(secs == 0){
                if(mins != 0){
                    secs = 59;
                    mins -= 1;
                }else{
                    if(hours != 0){
                        hours -=1;
                        mins = 59;
                        secs = 59;
                    }
                }
            }else secs -= 1;
            Sleep(CLOCKS_PER_SEC-30);
        }else break;
    }
    system("cls");
    cout << "Assignment Due!!!!";
    cin.get();
    return 0;
}
Freaky_Chris 299 Master Poster

Use std::string with getline

#include <string>
...
std::string myString;
getline(std::cin, myString);

Hope that helps

Chris

Freaky_Chris 299 Master Poster

Does this have to be cross platform? You are kind of confusing me when you say
3- how about clearing the screen ??...without the use of systm("cls"), how do u thinki can write in windows?

Gives the impression its just for windows. But other things say linux too...

Freaky_Chris 299 Master Poster

1)

int *myArray;
int n;
cin >> n;
myArray = new int[n];
....
delete [] myArray;

2)

sizeof(myArray)/sizeof(int)
Freaky_Chris 299 Master Poster

1) http://www.cplusplus.com/reference/clibrary/cstdarg/
2) Application Programming Interface - google it
4) Not a great deal, take XNA development for example.It uses C# the only differnce with developing windows applications to Xbox360 applications is that fact thatyou have to account for the different controller

Chris

Freaky_Chris 299 Master Poster

WTF, I went into your program and changed the 2 to a three and my computer started beeping about 3 times a second and printing off weird symbols on the console, i nearly messed myself

Thats because his loop still counts to 4 :P

Freaky_Chris 299 Master Poster

My exact thoughts but hey if it gets him to do his own work in future lol

Freaky_Chris 299 Master Poster

It's down to you to check the state of the shift key and caps locks. So i suggest you do that :P

Chris

Freaky_Chris 299 Master Poster

So where are your failed attempts, that was the point being made....we didnt say write it correctly then show it us...we said have a go and show us what you have and what it is you are having problems with

Freaky_Chris 299 Master Poster

What exactly do you mean by subset? as in are you trying to list all the different permutations of the numbers?

Freaky_Chris 299 Master Poster

It should be noted that short of speed, you really need to consider how safe fprintf is. Just remember that read chuncks of data at a time is somewhat faster than reading 1 bye at a time

Chris

Freaky_Chris 299 Master Poster

Yer I think i'm going to go with something like that. Although it will be slightly different i'll just have a variable within my class that marks if it was found or not. Since that was only an example i'm actually overloading the operator[] so passing another parameter is kind out of the question lol.

Thanks for the input
Chris

Freaky_Chris 299 Master Poster

Perhaps you should read the entire file in, strip out all html tags as you do so, that way you are left with just text. The go over and process what you have for sentences. But as ddanbe said, this isn't really a job for C++

The closest you will get to checking for the start and end of a sentence is [dot][space][capital] you will need to use that to check for both the beginning and end.

Chris

Chris

Freaky_Chris 299 Master Poster

Glad you got it fixed, just remember the number is the amount of array slots you get starting from 0...not what you get upto and including

ps mark as solved
thanks,
Chris

Freaky_Chris 299 Master Poster

I had already though of that, but what if T is a string? Since T could be absolutely anything I don't know what to do, it could be a class..

class...hmm maybe I should just return the default constructor for T?
T();

Chris

Freaky_Chris 299 Master Poster

OK, I've been looking at templates recently and eveything was fine...never had a problem with them at any point. But then when I decided to write a function that would either return the given template type or not. the following code explains what I mean.

template <class T>
T find(char x, T array[]){
  string str = "hello";
  for(int i = 0; i < str.length(); i++){
     if(x == str[i]) return array[i];
  }
  // if it's not I need to return something...but what?
}

I hope that makes sense all thanks

Chris

Freaky_Chris 299 Master Poster

we prefer to use strings with getline but there we go, it's a much more reliable solution since you don't have to worry about size

string test;
getline(cin, test);
cout << test.length();

Chris

Freaky_Chris 299 Master Poster

Just a stab, when you move do you redraw the gun? cause you will need to.

Chris

Freaky_Chris 299 Master Poster

Seems wird it should work fine. Try clicking re-build

Chris

Freaky_Chris 299 Master Poster

2D enough for you?

vector< vector<int> > v;

    for(int i = 0; i < 10; i++)
        v.push_back( vector<int>() );

    for(int i = 0; i < v.size(); i++){
        for(int x = 0; x < 10; x++){
            v[i].push_back(x*i);
        }
    }

    for(int i = 0; i < v.size(); i++){
        for(int x = 0; x < v[i].size(); x++){
            cout << v[i][x] << '\t';
        }
        cout << endl;
    }

Chris

Freaky_Chris 299 Master Poster

Chris

edit: just add one to the number lol and loop through??