Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>No it isn't because void main() is not allowed by either C or C++ standards. It
>never was, and never will be. There are compilers that will not allow void main().
>The program returns an integer whether you want it to or not.
I was arguing the same with Narue and found out that this is not true for freestanding environment: http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#2.1.2.1

Those programs are written with embedded compilers, which do not compile with C standards. There are a whole host of exceptions to the standards for compilers that target embedded systems. AFAIK no one here at DaniWeb use such compilers. And here is one such compiler that does not fully conform to C standards, and their web site explains why.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>is just as valid a program as
No it isn't because void main() is not allowed by either C or C++ standards. It never was, and never will be. There are compilers that will not allow void main(). The program returns an integer whether you want it to or not.

>>and you need to indicate, that's exactly what stderr is for.
Not really -- if your program is not called by another program then just sending an error message onto the screen might be sufficient. But many programs are launched by other programs -- on *nix machines there is a whole family of spawn functions, and on MS-Windows there is CreateProcess() and several others. Those program often wait for the spawned program to exit and then get its exit status. That will be broken when the spawned program just returns some random value from main().

The tiny programs you write in high school and college are not very significant and more than likely are never spawned by other programs. In those cases it doesn't really matter what you, the programmer, do. After you graduate and start working for software companies you will not be allowed to write programs as you see fit. You will be required to write programs according to company coding standards. Those coding standard will dictate how you code programs and in what format. They mey even tell you how to name variables, functions, c++ classes and a whole host of requirements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you only want it to do something every hour, then put it to sleep for an hour - this is MS-Windows, *nix would be sleep() with lower-case 's'.

while ( 1 )
{
    Sleep(60*60*1000); // sleep for one hour
    // stuff
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Father, forgive him because he knows not what he is doing.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I know that could be done with Microsoft MFC. Probably even wxWindows. You might search www.codeproject.com to see if they have anything useful. I know they have a plotting program written if MFC.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is that variable buffer disappears as soon as that function goes out of scope (returns) and the return value is an invalid pointer. Can't do that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> while ((pos < tope) && (strcmp(NombreBuscado, article[pos].name)!=0))

variable article is not an array. Change article[pos].name)!=0 to article.name)!=0

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AD: *t = _totoupper(*s); I don't know that function, please tell me about it :P

See the link in my post #4

tux4life commented: Yes, but they don't mention _totOupper, only: _totupper :P +15
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I already did suggest another solution -- and No you can not just simply remove the static keyword.

TCHAR*  MyToUpper(TCHAR *input, TCHAR* buffer) {     
  TCHAR *s = input;                
  TCHAR *t= buffer;               
                                   
  while (*s != '\0') {             
    *t = _totoupper(*s);           
    s++;
    t++;                           
  }     

  *t ='\0';
  return buffer;                   
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> *t = _toupper(*s);
You still didn't use the right function. Read my previous post

tux4life: That's a common problem with several standard C library functions, such as strtok() and localtime(). A better design is to have the calling function pass in a buffer for the destination string.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use _totupper(), which is portable between char* and wchar_t* Also, you need to null-terminate the string after that loop terminates.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ODBC is the oldest and most widely used database access method, it is supported by virtually all SQL databases. DAO and ADO are both slightly faster than ODBC but not as widely used except in Microsoft databases such as Microsoft SQL Server and MSAccess. Others might use it too, I don't know.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is no such data type as "tchar". Do you mean TCHAR that is defined in tchar.h? If that is right, then TCHAR is defined as either char* or wchar_t*, depending on if the program is compiled for UNICODE or not.

And to answer your question, no that function will not work. What happens if the string contains characters other than 'a'-'z'? What you need to use is toupper() defined in ctype.,h

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes I did mean strtok(), not strchr() :)

I understand what you mean now.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean like BoundsChecker ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have not been able to duplicate those warnings with my compiler.

I don't know why strtok() will not work for your program. Here is an example of its use

char iobuf[] = "Hello World";
char *ptr = strchr(iobuf, " ");
while( ptr != NULL)
{
     printf("%s\n", ptr);
     ptr = strchr( NULL, " ");
}

Note that you pass a pointer to a char array the first time, and NULL thereafter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the destination machine is MS-Windows system, then you could encrypt the password and store it in the registry.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are getting that seg fault because
line 51: allocate memory to temp
line 52: toss the memory away and reset pointer to somewhere in base_string or NULL
line 65: returns a pointer to the pointer returned by line 52 + the length of char* delim, which could result in an out-of-bounds error. This final pointer can not be free'ed because it doesn't point to the same address that was returned by calloc() or malloc(). So the memory allocated on line 51 is unusable.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I gave you my advice and opinions -- take it or leave it, I don't care because its your buggy program not mine.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why do you want to release something that belongs to the operating system? Programs don't normally have any control over paging system.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That would be the same code as a set() function. No point coding the same thing twice.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When you compile programs with Microsoft compilers in DEBUG mode the compiler will fill pointer addresses with that value 0xcdcdcdcd or some such value like that to indicate that address has not been used. if you code something like this char *ptr = 0; then the address will be 0x0000, as expected, but char* ptr the address is set to 0xcdcdcdcd.

If you are going to test the validity of that pointer, then declare it like this: GridGeneration *finalgrid = 0; or GridGeneration *finalgrid = NULL; , both are equivalent.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
private:
	vector<short>& base_row;      
	vector< vector<short> >& base_mat;   // Where all the elements of matrix are located.

references have to be initialized in the class constructor. I suspect you do not want those to be references, so remove the & reference operator. for (vector<short>::iterator it_1d = base_row.begin(); it_1d<base_row.size(); it_1d++) That is the incorrect way to check for end-of-vector. Test the iterator against base_row.end(), not .size().


There are several other errors, but you should be able to correct those yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

nanchuangyeyu: One reason for all those errors is because you need using namespace std; before including matrix.h or add it inside matrix.h. In that header file you could also just specify std:: before any STL templates, such as std::vector<std::vector<int>>

nanchuangyeyu commented: generous help,thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the library must be like this:
#include <iostream.h>
all of the library should have a .h or header

I normally don't give negative rep, but I couldn't help myself this time because your post is 100% wrong. Only an ancient compiler would use c++ header files with .h extension.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I really love codeproject.com, if I need a code snippet or example program for MS-Windows that is the very first place I look., and I can usually find something that I can use. codeproject has the best online repository of MS-Windows programs/functions/libraries that I know of.

IMHO Digital Point sucks. I've browsed around there before and it seems to have a lot of spam in all its forums, and its moderators could care less. They will ban a user, including long-time posters, at the drop of the hat for the littlest infraction of their rules. One of their rules I do like -- no "me too" posts, they are deleted and posters infracted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No special name for it -- its name can be almost anything. All it would do is change the value of a variable from one value to something else. And you can code a change method any way you want, or not at all. I normally do not include a change function -- just use the set function to change a value.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>send(sock, bufEnviados,strlen(bufEnviados), 0 );

strlen() won't work on unicode strings. usel (wcslen(bufEnviados)+1) * sizeof(wchar_t) instead. wcslen() is declared in wchar.h -- I don't know if it is portable to all compilers or not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Haven't seen any for what i want to do, moving my models with bones. Do you know of any?

BattlingMaxo

Sorry but I know virtually nothing about OpenGL.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just found a situation where FF is worse then IE8 right here at DaniWeb. In one of the posts FF displays blank pages while IE8 the pages are ok. I think its a situation where FF takes longer then IE8 to render the page because FF takes several seconds to render the page correctly.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Repost anyway -- one misplaced semicolon will cause big problems.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the function again

char * ustrtok(char *base_string,char *next_str,char *delim)
{
char *str2;
str2=(char*)malloc(100);
if(base_string==NULL && strlen(base_string)<1)
{
next_str=NULL;
return NULL;
}
int len=strlen(base_string);
char *temp;
temp=(char*)malloc(100);

temp=strstr(base_string,delim);
if(temp==NULL)
{
strcpy(next_str,base_string);
next_str[strlen(next_str)]='\0';
return NULL;
}
else
{
int sub_len=temp-base_string;
str2=(char*)malloc(100);
strncpy(str2,base_string,sub_len);
str2[strlen(str2)]='\0';
strcpy(next_str,str2);
return (temp+strlen(delim));
}
}

line 5: That line will cause a crash when base_string is NULL because the second part of that statement will call strlen() with a NULL pointer. Need to use the || operator, not &&.

line 7: that does nothing but set the local copy of the pointer to NULL. When the program returns that pointer disappears, and nothing at all happens to the pointer in the calling function. And even if it did work (which it doesn't) it would cause memory leaks in the calling function. This is one reason I said that pointer needs to be char** instead of char*.

line 14: memory leak because it discards the memory allocated in the previous line.

line 18: unnecessary and can be deleted because the previous line strcpy() will null-terminated the string.

line 24: another memory leak. It was already allocated on line 2.

line 28: another memory leak -- what happens to the memory allocated on line 24???

And in the places where this function is called, I don't see where the memory for that second parameter is ever free()'ed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Unless of couse your writting portible (and standard) code that should run on any compiler/OS. :)

But that's rarely the case, especially with newbe programs. And IMHO its always a good idea to mention them in any case.

Hiroshe commented: Can't argue with that +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try the rename() function. i haven't tried it on the recycle bin so it might not work without changing the folder's permissions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ustrtok() is broken pretty badly. memory leaks, using uninitialized char pointers, and the second parameter should be char**, not char*

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That program has a considerable number of errors, bugs, buffer overruns, and memory leaks. I was finally able to get it to read the first file, after correcting all those many problems. (using VC++ 2008 Express on Vista).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I did not ask someone to write the code for me. I used the term "collaborate." I am wiling to do the "heavy lifting" but just needed guidance. Nonetheless, never mind. I will pursue a different route.

Respectfully

You have to know what it is that you want before anyone can help you. There are lots of sort algorithms and billions of things to sort. We obviously have no idea what it is that you want sorted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Later I moved into a development gig and learned Visual C++ was not for me.

It takes some time to learn how to use that IDE and compiler. And its not a computer language, just a compiler. There are others, such as Code::Blocks.

>>How can I get me career 'back on track'?
You may or may not be off track. Just because you got one rejection doesn't mean you are off track. Did you meet the minimum qualifications the company wanted for that job? This is an employer's market right now -- too many people wanting not enough jobs so they can afford to pick and choose. You didn't mention your age or education, maybe you need to get back in school and get another degree. Also, maybe you will have to move somewhere else to get a job you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What other criteria could there possibly be? Sort algorithms are almost the same regardless of what is being sorted. Its the data swaps that are the main difference.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
for(int run = 0; gamemenu != run;)
	{
		if(gamemenu == 1)
		{
			gamestart();
		}

That is an infinite loop because gamestart() never changes the value of gamemenu, nor does it really do anything at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There have been many major changes to MFC since that compiler was released. I started learning it by doing the Scribble Tutorial

That tutorial will not be useful on VC++ 2005/8 compilers.

colmcy1 commented: Thanks for all the great help, much appreciated +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Aren't there openGL tutorials you can use for animation?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please attach the file -- not post it. To do that hit the "Go Advanced" butten, scroll down until you see "Manage Attachments" button. That will let you browse your computer file system for the file to upload. Attempting to recreate the file(s) from what you posted can cause a lot of errors.

Salem commented: I admire your perseverance, I gave up caring about this thread a long time ago. +36
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post code -- that program works ok for me using vc++ 2008 express compiler. What compiler are you using?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Are you sure the Button is in CMainFrame?

Dialog projects do not have a CMainFrame class (assuming he created a dialog project, not SDI or MDI)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 29: you are passing FileName array, which only contains the name entered from the keyboard on line 14. You need to pass filename which is formatted on line 19.

Do you really want all those commas in the filename?

That code then should look like this:

#include <fstream.h>
#include <iostream.h>
#include <stdio.h>
#include<conio.h>


int main()
{
    char FirstName[30], LastName[30];
    int Age;
    char FileName[255];
    char filename[30];
     cout << "\nEnter the name of the file you want to create: ";
    cin >> FileName;
    int a=1,b=2,c=3;
    
    sprintf(filename, "%s, %i., %i., %i.txt",  FileName, a,b,c);

    cout << "Enter First Name: ";
    cin >> FirstName;
    cout << "Enter Last Name:  ";
    cin >> LastName;
    cout << "Enter Age:        ";
    cin >> Age;


   
    ofstream Students(filename, ios::out);
    Students << FirstName << "\n" << LastName << "\n" << Age;

    cout << "\n\n";
    //}
    
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
a = GCD(n1,n2);
	b = GCD(n1,n2);

The values of a and b will be the same because the values of n1 and n2 do not change between the function calls. There is no point in calling GCD() twice with the same parameters.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster


Sorry i still can't print the values of a, b and c as part of the filename it saves the file with the user specified name but not the integers. Can you please comment on it.
Many thanks

Stop whining about it and post the code you tried. Do you really think we can see the code on your monitor :icon_eek:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>In my post#1 every thing described properly.
Then why didn't your program like it?

I don't want to create the file myself, I want to use the one YOU created.