Duoas 1,025 Postaholic Featured Poster

Ah, the loop ends at the space because the string ends at the space. scanf stops reading input at spaces. So when you enter "1234 432" the userString gets "1234", and " 432" is left waiting to be read.

If you want to get a string from the user try using fgets().

Good luck.

Duoas 1,025 Postaholic Featured Poster

Add writeln( ShortDateFormat ); to your code and see if it reads something like yyyy/m/d .

Also please look again at this thread, down at the bottom of the first post where it says "Convert From A String".

Sorry I've been so busy, altzaportu. I'll respond to you more later...

Duoas 1,025 Postaholic Featured Poster

I too fail to see how complaining about the OP's tools helps him answer his question. There is no need to give him/her a hard time.

In the real world of capitalism, choice of toolset is entirely dictated by business concerns. Nothing else. Business [or school] issues dominate technical issues. Period.


stackOverflow
There are three answers to your problem --two that you have already found.

  1. Use outtext and/or outtextxy along with setviewport to draw the text graphically on the screen but keep it bounded into an area. You will probably also find the textwidth and textheight functions useful.
  2. Switch to text mode to display it, and return when done.
  3. Use the BIOS functions to dump the text onto the screen. Even though you are in a graphics mode, the video BIOS can still write to the screen as if it were a TTY.

For option 1, you might want to check out this thread, where that OP had a similar question.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No, you've completely missed the concept of argv.

argv is an array of strings (where a string is a pointer to char). It is not safe to change argv.
argc is the number of items in the argv array.

argv[0] is the program name.
argv[1] is the first argument.
etc.

This might help you.

#include <stdlib.h>
#include <stdio.h>

int main( int argc, char *argv[] ) {
  int i;

  printf( "My name is: %s\n", argv[ 0 ] );

  for (i = 1; i < argc; i++)
    printf( "arg %d: %s\n", i, argv[ i ] );

  return 0;
  }

You can test it:

D:\prog> a
My name is: a

D:\prog> a Hello world!
My name is: a
arg 1: Hello
arg 2: world!

D:\prog> ren a.exe carlos.exe

D:\prog> Carlos de la Paz Gutieres-Hernandez
My name is: Carlos
arg 1: de
arg 2: la
arg 3: Paz
arg 4: Gutieres-Hernandez

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I feel like a total geek. I always use python straight from the command-line.

Duoas 1,025 Postaholic Featured Poster

I don't have Vista, so I can't exactly identify what part of the OS is giving you the problem.

IDLE uses a feedback loop socket. This is a weird thing to do, so antivirus and internet access filters (like ZoneAlarm and the like) complain. Vista has a lot of protocol built-in about what can connect to the internet and how. Even though IDLE isn't actually dialing out...

Find your internet connection wizard/control panel/whatever Vista uses and make sure that IDLE is permitted to access the internet any way it darn well pleases...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The first is local data you can edit (since the array is local data).

The second is a local pointer to global, static (constant) data. You are not allowed to modify constant data.

If you have GNU C, you can compile with -fwritable-strings to keep the global string from being made constant, but this is not recommended.

Duoas 1,025 Postaholic Featured Poster

Don't worry about it.

I'm not sure exactly why the problem occurs either. But the type was being mangled incorrectly without the explicit cast.

I added a tellg() statement after the seekg() to see where the fp was, and I was getting some really large number, which showed me that it was not seeking from eof properly. So I checked the type of sizeof() against what the function wanted in order to find the error. I think that the problem is one of those "gotchas" from using templated objects.

Alas.


For the namespace problem, it sounds like you have already used something like using namespace fooey; or using namespace std; or one of the headers you imported did it for you, so if you try to say using namespace std; again it looks in the local namespace and says, basically, "std doesn't have any namespace called 'std'".

You can fix it by explicitly referring to the global namespace: stfile.seekg( -([B]::[/B]std::streamoff(sizeof(item))), [B]::[/B]ios::end ); or by (if you are using std) just stfile.seekg( -(streamoff(sizeof(item))), ios::end ); That could fix it. (Of course, your solution, by using an intermediate/temporary int works as well [obviously], because the compiler could properly promote the int type to streamoff.)


For the binary stuff, try running your program without the binary I/O and entering the number 10 in answer to either price and/or stock. You'll see that it doesn't write 40 bytes, but 41 or 42. This is …

Karkaroff commented: thanks! that clears things a bit +1
Duoas 1,025 Postaholic Featured Poster

Ah, yes, it is the beginning of the year... so you should be at the beginning of your programming course and not at the end...

Sorry I went over your head.

The basic principles are:

  1. always read user input as a string, using something like getline( cin, s );
  2. test the string to make sure the input is valid
  3. convert the string to the proper type of thing (integer, float, enum, etc.)

This is not lighthearted stuff. But all robust code that interfaces with the user must have it in some form. In academia people get away without it because the focus is often on other things.

There are as many ways to check input as you can think of. You could, for example, just create a function that tells you if it is good or bad.

getline( cin, s );
if (!isanumber( s )) { cout << "fooey!\n"; return; }
n = converttonumber( s )

Somewhere else you'd have defined the handy little functions isanumber() and converttonumber() to help you. The abstraction and organization of your code is up to you.

T.N.Sharma Be careful:

  • Get rid of that cin>>scores; ! It's pure evil, and getting rid of it is the whole point of this thread.
  • The argument should be char scores[] .
  • Don't hardcode ASCII values. Use '0' and '9' .
  • Your function tries to do two things but succeeds with only one.
    1. if your function determines …
Duoas 1,025 Postaholic Featured Poster

He's using ISO-standard C++, so everything he does you can do. However, the code he provides isn't in the same order you would put it in your program, just in the order he tells you about it.

The basic strategy is that you should read all user input as a string.

#include <iostream>

int main() {
  std::string user_input;

  std::cout << "How many years old are you? ";
  std::getline( std::cin, user_input );

  return EXIT_SUCCESS;
  }

At this point, the user could have entered anything --including nothing by just pressing the ENTER key. However, since we can expect users to do dumb stuff like that, we have obtained input in a safe way: the program is still working properly.

Now, we need to verify that the user gave us a string that is correctly formatted. Since we are asking for a number, let's create some way to verify that the user did, in fact, enter a number using the digits 0..9. I'll use the same kind of technique referenced in the article.

#include <algorithm>
#include <iostream>
#include <cctype>

// This is just a fancy way of making a function that returns
// true if c is not a digit in '0'..'9'. Except, instead of a function,
// it is an object.
class nondigit {
  public:
    bool operator () ( char c ) { return !isdigit( c ); }
  };

int main() {
  std::string user_input;

  std::cout << "How many years old are you? ";
  std::getline( std::cin, user_input );

  // …
Duoas 1,025 Postaholic Featured Poster

Ah, young grasshopper, you have advanced to the next level: you have recognized the need for better input validation.

It might be worth it to make yourself a little function that reads and returns a validated number.

Duoas 1,025 Postaholic Featured Poster

Nice! Boost rocks!

Sorry I wasn't paying attention when I responded earlier...

Duoas 1,025 Postaholic Featured Poster

Karkaroff, we're trying to help you. There is no need to get snippy.

I've spent some time debugging this for you. The problem is that the compiler is tripping over the type of the offset value when you seek to the last record on line 25. Change it to stfile.seekg( -(std::streamoff(sizeof(item))), ios::end ); That should get you rockin'.

Also, when I wrote stfile.open( "fooey.dat", ios::in | ios::out | [B]ios::binary[/B] ); i meant it. Play with fire and you'll get burnt. Keep your hand in the fire and you'll get toasted.

[EDIT] Nice links, iamthwee. Karkaroff hasn't violated any serialization rules though...

Oh yeah, while I'm still thinking about it (for the nth time), replace that gets(name) on line 19 with cin.get( name, sizeof( name ) ); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I think the original problem (causing the compiler error) is this: EventStream<complex<Lambda[B]>>[/B] evstrTrain( ... C++ compilers can't distinguish this from the right-shift operator. You need to have a space between them: EventStream<complex<Lambda[B]> >[/B] evstrTrain( ... Hope this helps.

iamthwee commented: good catch +13
Duoas 1,025 Postaholic Featured Poster

There is no button in graphics.py. How exactly are you trying to create one?

Duoas 1,025 Postaholic Featured Poster

It will also fail if the file "stock.txt" doesn't exist before you start, since there is nothing to read and you haven't reset the error condition.

Duoas 1,025 Postaholic Featured Poster

You have to do some planning on how exactly your messages are to be formatted (more information than just text must be sent).

Use an INET, STREAM socket. Avoid datagrams.

You will have to have a server running on some system everyone can access, which accepts connections and duplicates information received from one connection to all the appropriate target connections. You may or may not choose to use threading to implement each connection.

For the 3D stuff, you will want some sort of library. Here's some C++ 3D stuff I googled. The OpenGL things might be most friendly to you.

You've got some work ahead of you. Implementing a 3D chat is not trivial. Relatively simple, yes, but not fare for the queasy beginner.

Hope this helps.

[EDIT] Hey there, iamthwee. Are you also thinking, "gee, this could be done in Blender"? :)

Duoas 1,025 Postaholic Featured Poster

You are not properly initializing your fstream. Try: stfile.open( "fooey.dat", ios::in | ios::out | ios::binary ); I'm still a bit dubious about what you are doing in your code. (There's nothing wrong with writing an object to file like you are; it's just that your code looks really scattered.)

Hope this helps.

[EDIT] BTW. How did this thread get a four-star rating from only ~40 views and no responses?

Duoas 1,025 Postaholic Featured Poster

You're kidding, right? You demand us to help you in less than two hours? Go get a job and see how long people put up with you.

Since you fixed it yourself I won't bother giving you my answer.

Salem commented: Absolutely correct! +15
Duoas 1,025 Postaholic Featured Poster

Link.

Pay special attention to the section on "Reading and Writing Complex Data". You are interested in integers, but the same principles apply. Here's their example using int instead of Data.

#include <fstream.h>
    ...
    int x;
    int *y = new int[10];

    fstream myFile ("data.bin", ios::in | ios::out | ios::binary);
    myFile.seekp (location1);
    myFile.write ((char*)&x, sizeof (int));
    ...
    myFile.seekg (0);
    myFile.read ((char*)y, sizeof (int) * 10);

Good luck.

Sawamura commented: thx for the link and code +1
Duoas 1,025 Postaholic Featured Poster

When in doubt, read the documentation.

I just did, and realized I made an error. It should be: cin.ignore( numeric_limits<streamsize>::max(), [B]'\n'[/B] ); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The C++ >> I/O operator corresponds to the C scanf() function. It is not really designed to input strings or binary data, even though you see it all the time.

A good reference (especially in C++) is invaluable.
I like cppreference.com, because it is simple. For more detail, check out cplusplus.com.

The .read() is a method of the istream class.

There is also a sticky thread at the top of the C++ forum for books you can get, and you can google for c++ tutorials. These will help you out a lot.

Good luck.

Duoas 1,025 Postaholic Featured Poster

The >> and << file operators only read until it encounters the next non-whitespace object in the file. In your case, it is the word "RECORDS".

Your buffer is 1000 characters long, so you cannot read more than 1000 characters at a time. So, try this instead:

...

        char txt_records[1000];

        ofstream file_records_writin("records.txt");
	file_records_writin
          <<"\t\t\t\t\tRECORDS\n"
          <<"name-------------------------------time\n\n"
          <<endl;
	file_records_writin.close();

	ifstream file_records_readin("records.txt");
	file_records_readin.read( txt_records, 1000 );
	cout<<txt_records;

...

You would be better off, though, reading each record one at a time, using getline().

I hope this helps.

Duoas 1,025 Postaholic Featured Poster

It looks good as is to me.

However, you really should get rid of that <conio.h> stuff. It is not a good idea to mix C++ and C I/O. If you really must have a getch() type thing in there, use one of the C++ methods to do it.

best: cin.ignore( numeric_limits<streamsize>::max() ); also good: getline( cin, foostr ); cin.get( foochar ); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Say nret = connect(sock, NULL, 0); C++ defines NULL as a pointer.

Duoas 1,025 Postaholic Featured Poster

C++ is a little bit more strict about how it defines NULL than C. The compiler is complaining because you are passing a (void *)0 as the third argument, when it expects an (int)0.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

RajatC
Please take the time to look up information if you don't recognize something, rather than hijack someone's thread. string::npos is a STL object used to mean any index at or past the end of a string.

anallan
You actually have the right idea, but you made three (small) mistakes. The code in question is here:

for (int k = 0; k != j; k++){

          int i = firstStr.find(secondStr[k]);

          int gPos = i;

          if (gPos != string::npos){

                   while (gPos != string::npos){

                         newStr = firstStr.substr(0,i);

                         newStr += firstStr.substr (i + j);

                   }

          }else break;

    }

Your correct idea is to first find the index of the current second string character (you do this on line 3) and if the character is found in the first string (line 7) you want to erase it.

Your second correct idea is that you don't want to move on to the next character in the second string until you have eradicated all occurrences of the current second string character out of the first string.

Your first mistake is the position of the loop (line 9). Currently, gpos will never change. Every time you loop you need to update gpos just like you did on lines 3 and 5. (It will be easier if you get rid of the variable i and just use gpos.)

The second mistake is how you attempt to get rid of the found character in the first string (lines 11 and 13). WaltP correctly …

Duoas 1,025 Postaholic Featured Poster

The easiest way to compare two strings depends entirely upon your assembler.

Chances are though that you might do just as well to write it yourself. First you need to have a good 80x86 assembly opcode reference. Here's a good one I found on Google.

I recommend you check out the repe cmpsb string command. It is used to compare two strings for equality.

Also, listen to Ancient Dragon. He knows what he is talking about. Unless you know exactly what tricky stuff to do, you must do it as he suggested: read the source file while writing a new file. Once done, you can delete the source file and rename the new file to have the same name that the source file did, if you want.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Unfortunately, the "Julian Day Number" is one of those terms I mentioned (or rather, it is often abused to mean "the day of the year").

Fortunately it looks like that link uses the JDN correctly! Nice catch!

Duoas 1,025 Postaholic Featured Poster

It is a standard POSIX function. It is not a standard C/C++ function.

See Wikipedia for more. Be sure to click on the first few links down at the bottom in the "See Also" section too.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Python deals only with the Gregorian calendar. Certain terms (like "Julian") can be properly applied to specific things withing the Gregorian system, but the Julian calendar it is not.

Usually the Proleptic Gregorian calendar serves well enough for modern computing tasks...

Try googling "gregorian julian" for conversion algorithms. Good luck.

Duoas 1,025 Postaholic Featured Poster

Agreed, but when dealing with new programmers I have learned by experience (teaching and tutoring) that debugging works best once a firm concept of what should be happing is established. Anyway...

iamthwee commented: Well said +13
Duoas 1,025 Postaholic Featured Poster

I always take it a step farther and just tell people to forget the code. Get out the paper and crayons first, draw what must happen, then write the code to do exactly that.

Disentangling new programmers from bad code is more difficult and confusing than just going through the steps of writing the code correctly to begin with...

Duoas 1,025 Postaholic Featured Poster

The Pos and AnsiPos functions require string arguments. Not char. Make sure you are using strings.

Duoas 1,025 Postaholic Featured Poster

I was going to say that sleep() isn't in section 5 of the manual...

heh heh heh :)

Duoas 1,025 Postaholic Featured Poster

A university is a type of school, so it is schoolwork.

While your code works, I think you are trying to do too many things at once. For example, the procedure searchTitle should not create the file also, even just for testing. Create a procedure that creates/writes the file from the book array (say, ArchivarLibros), and another that reads it into the book array (say, LeerLibrosDeArchivo). Then, if you want to just make a file for testing, create a procedure that is called first which fills the array and saves it to file with the ArchivarLibros procedure.

You will also want to use a dynamic array instead of a fixed array. Dynamic arrays in Delphi always begin at zero, not one.

Whenever you find that you are doing something over and over, that is a good hint that a small function or procedure might be handy. For example:
[[I][/I]code=Delphi[I][/I]]

function PedirConfirmarONegar( msg: string ): boolean;
  var
    respuesta: string;
  begin
  { La falla es fracasar, para un compiler feliz }
  result := false;

  { Pida el mensaje }
  writeln;
  writeln( msg );
  write( ': ' );

  { Repita hasta una respuesta correcta }
  repeat
    readln( respuesta );
    case upCase( respuesta[ 1 ] ) of
      'Y': begin
           result := true;
           break
           end;
      'N': break
      else begin
           writeln( 'Please answer YES or NO' );
           write( ': ' )
           end
      end;
  until false
  end;

[[I][/I]/code[I][/I]]

OK, now for your actual question. You want to search titles for substrings. In Delphi, …

Duoas 1,025 Postaholic Featured Poster

Ah, this is an interesting problem. I have to go somewhere right now, but I'll give you some attention later today.

Is this schoolwork? Or is it business? (I'll make you work harder if its for business, since commercial programs must be much more robust than school programs...)

Hasta luego.

Duoas 1,025 Postaholic Featured Poster

My best guess is that the argument is a "type-cast expression" (according to MSDN), which always takes the form: [B]([/B][I]typename[/I][B])[/B] This makes a semantic difference when lexing/parsing types like struct foo and int * .

I'm not too sure though... I've never cared enough to get that deep into it, as it is always legitimate to surround any sizeable expression with parentheses...

Duoas 1,025 Postaholic Featured Poster

> Hi
Hi.

> I want to read a pascal file a find a certain word in that file.
Many people would like to do that.

> Thanks
You're welcome.

Link. (Show me what you've done to solve your problem and I'll show you some help.)

Duoas 1,025 Postaholic Featured Poster

Line 19 should read newp = (nameval_t *) malloc( sizeof( nameval_t ) ); This is why I recommend just always using parentheses with sizeof. It always works with parens, but makes a difference without...

n.aggel commented: thanks for your help!! :) +2
Duoas 1,025 Postaholic Featured Poster

Eh, why not?

[[I][/I]code=C++[I][/I]]

switch (pnlCards.Tag) {
  case 0:
    result = prediction;
    break;
  case 1: case 2: case 3: case 4: case 5:
    TPanel p  = (TPanel)(pnlCards.Controls[ pnlCards.Tag ]);
    TPanel p0 = (TPanel)(pnlCards.Controls[ pnlCards.Tag-1 ]);
    if (p.Tag > p0.Tag)
      result = higher;
    if (p.Tag < p0.Tag)
      result := lower;
    if (p.Tag == p0.Tag)
      result := pair;
    break;
  }

[[I][/I]/code[I][/I]]

I took a single liberty to make typing easier. This code could be much better written in both Pascal and in C++.

Duoas 1,025 Postaholic Featured Poster

No, but I think there should be a comma at the end of line 22.

I've never directly made dialogues in an RC file though... If I'm wrong about line 22 I'll have to look it up.

Duoas 1,025 Postaholic Featured Poster

The InputBox() function is a nice wrapper for some simpler API calls. Try here.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I think that the compiler is complaining that it doesn't know what NumOfPlayers is, or believes it to be something other than a variable. Likewise in your argument list, one of them is not the type of thing it ought to be?

This can occur due to a syntax error (such as forgetting a semi-colon, or mis-matched braces, etc.) in some line above line 265.

It can also occur, amazingly, if you have whitespace other than spaces, tabs, and CR and LF in the lines, and sometimes if you don't put spaces between the "switch" and "(" ---I think, but I am not sure. GCC shouldn't have these problems...

Duoas 1,025 Postaholic Featured Poster

You are making two errors:

1.
The type of Q.Data[n] is a Flight (aka ItemType) --not a pointer. You cannot assign NULL to a struct.

When I tested it, the following compiled correctly: Q.Data[i].C_TIME = 0; (which is what you were complaining about, so I cannot replicate your problem).

2.
Your for loop has a fencepost error. It should be: for (i = 0; i < MAXSIZE; i++) Also, I would recommend against using typedef gratuitously. If ItemType is a Flight, then use "Flight" in your QType structure, instead of renaming it to something else...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I'm not sure how I have failed to address your problem.

In both your first and your latest post, you indicated that you need to do three things:

  1. Copy specific tables to a backup location
  2. Rename the backup tables with a timestamp
  3. Delete really old backup tables

The link article I gave you specifically deals with 1 and 2, which can be done at the same time. Further, the article is aimed at making a full copy --where it is not cross-linked between the old table and current data-- which is what a backup generally entails. The article deals with Paradox tables using Delphi.

To delete an old backup table, delete it just as you would any other table.

If I have misunderstood your problem please try to be more specific about exactly what it is that you are trying to do.

Duoas 1,025 Postaholic Featured Poster

Here's a Delphi Corner article that may help you.

Personally, I dislike playing with databases... so my knowledge is a bit weak in this area. Let me know if it helps.

Duoas 1,025 Postaholic Featured Poster

This is the Pascal language subforum.

What programming language are you using? And what database are you using?

Duoas 1,025 Postaholic Featured Poster

Use function overloading:

void LoadFile( std::string filename, std::string key )
{
  // blah
}

void LoadFile( std::string filename )
{
  LoadFile( filename, filename );
}

Have fun!

Duoas 1,025 Postaholic Featured Poster

> I think you misunderstood the other poster.
> I don't think that word means what you think it means.
I amaze at the arrogance and rudeness some people possess. Do you really believe yourself superior to AD's intellect, and mine?

I don't really care much what you think. I know what the word inline means. Look it up yourself.

> The OP was using the way AD wasn't.
Thank you Captain Obvious.

sarehu commented: I think you misunderstood me, too. +1