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

wrong forum

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int main(int check) {
char comd;

Actually, the problem starts with the above two lines. main() must have either no parameters or two prameters int main(int argc, char* argv[]) There are no other options, except possible adding a third parameter which is normally an array of environment strings. And you are NEVER allowed to call main() from within the program. That function is reserved by the compiler to be the entry point into your program.

>> gets(pass1);
NEVER EVER use gets() in either C or C++ programs because it can corrupt your program's memory. It has no checks to see that you can type more characters into the array then the charcater array can hold. In C++ use either cin >> pass1 or cin.getline(pass1, sizeof(pass1)); >>goto over;
Replace that with the break statement. goto in C and C++ is considered to be poor coding practice.

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

line 27 and 28: you failed to open the files

ifstream inData("myfile.txt");
ofstream outData("outfile.txt");

>>"too few arguements to function

Carefully check and recheck the argument list in the function prototypes that appear at the top of your program with the parameter list that is passed on lines 37-40. There apparently are some discrepancies.

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

If you are attempting to add a new element to frameScores array, such as increase its size from 5 to 6 elements, then make frameScores a pointer and reallocate its size.

int* frameScores= {0};
int frameSize = 0; // size of frameScores
int totalScore = 0;
int lastFrameNumber = 0;

void addFrame(int toAdd)
{
         totalScore = totalScore + toAdd;
         if (frameSize < lastFrameNumber) 
         {
            frameScores = (int *)realloc(frameScores,(frameSize+1) * sizeof(int));
            frameScores[frameSize] = totalScore;
            ++frameSize;
         }     
}

int main()
{
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>int temp[sizeof(frameScores)+1];
That line is wrong. If frameScores is declared as int frameScores[5] then the above declaration will create an array of 5*sizeof(int) = 20+1 elements. What you want is 6 elements, so the line should be int temp[sizeof((frameScores)/sizeof(frameScores[0]))+1]; Well that will correct that line, but it still will not correct the line frameScores = temp; because the two arrays are not the same size.

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

Read the file into a linked list, sort it, then write it back out. That will work for files that are not very large. For really huge files (1+gig) there are file sort programs you can get (see google).

a) Read the words into a linked list of structures. If the word is already in the list then just increment the structure's counter variable member. If the word is not in the list, create a new structure and add it to the list in sorted order or just to the end of the list.

struct word
{
    char* sword;
    int count;
};

b) just iterate through the linked list and print out the words

c) If you add new nodes in sorted order then this option is the same as the previous one. Otherwise if you just added new words to the end of the list then you will have to sort the list first.

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

If you are calling that from some other function then expect to use the open file handle after that function returns, then the FILE pointer must be passed by reference. What you have coded is passing by value.

void OpenReportFile(FILE **reportFile)
{
*reportFile = fopen("c:\\temp\\report.txt","wt");
if (*reportFile == NULL)
{
    printf("Report file open request failed.\n");
    printf("Press any key to exit...\n");
    /* fflush(stdin);*/ <<<< BAD BAD BAD!!!
    getchar();
    exit(-10);
}
}

int main()
{
    FILE* infile = NULL;
    OpenReportFile( &infile );
    // Now you can use infile 
    fclose(infile);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How is frameScores declared?

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

> Searches is not the problem -- the problem is newbe confusion about what is and is not a code snippet. They are making normal questions code snippets without know what they are doing.
They were doing this before, too. The same percentage of people who see the code snippet option screw it up. The only difference is there's a larger group of people now.

This was never ever a problem in C or C++ forums before now.

> My suggestion is to remove that option when posting a new thread, or make it more difficult to create code snippets.
Similarly ... If people don't know understand to post a thread, make posting a thread more difficult to do? The idea is that we want MORE people to realize we have a free library where anyone can submit snippets ... not fewer. If people don't know how to do that, we educate those that don't. We don't hide the feature to make it hard for everyone.

No -- not createing a new thread more difficult, only creating code snippets. Newbes don't post code snippets -- only members who have been around for awhile do that, and they (should) know what they are doing.

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

Searches is not the problem -- the problem is newbe confusion about what is and is not a code snippet. They are making normal questions code snippets without know what they are doing. My suggestion is to remove the "What are you posting? " option that appears in new thread and create some other way to create code snippets.

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

Your program makes zero sense. Why are you using ofstream to write to a dll ?????:icon_eek:

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

I agree. They're just another road hazard for noobs to trip over as it stands.

Exactly my point -- see this thread.

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

I don't know about requiring mod approval before posting them, though. Take for example the C# forum -- we rarely have mods post in there so who would be the authority on approving those snippets? Plus if it was bad code they could just throw it in a thread anyway.

There are several mods who are responsible for ALL the forums in Software Development, whether they post in them or not. And I believe the snippets forums required mod approval anyway, but I may be wrong about that. That's the way it works in PFO.

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

>>BTW, how does c_str() work? I will read about c_str() later.
Don't read about it later -- DO IT NOW.

kvprajapati commented: Well said. +13
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A "code snipped" is supposed to be some code you have finished and want to show everyone else to help them solve a similar problem. That's why there are no "reply" or "quote" links in your thread so that others can help you. Unfortunately Dani has decided, unwisely IMO, to mix code snippets in the same forum as c++ questions, confusing people like you who really don't know the difference between them.

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

Good thing you proposed a challenging project. You will learn much more this way and your knowledge base will increase considerably. Don't be bothered about "biting off more than you can chew" ... u will choke, and then you will swallow , with pain, and you will be the wiser for it.

If he has all the time in the world I might agree. But there is a short time constraint -- I suppose the assignment has to be turned in before the class ends.

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

>>I still encounter problem with conversion of string variable to numeric variable using strtof() function call. It seems that that function requires a char instead of string for the conversion

If you had bothered to read the methods available to std::string you would have seen c_str(), which returns const char*. Next time read about the classes you are using instead of blindly tossing code to the screen hoping the compiler will fix your bugs for you.

And you should not have made this a "code snippet" because it ain't one.

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

There appears to be some confusion about what c++ code snippets are supposed to be. I've seen two threads already that are just normal c++ questions but posted as code snippets. I really don't like intermingling the c++ forum with code snippets for two reasons

  1. Much more difficult to find specific code snippets
  2. Newbe confusion about what is or is not a code snippet

IMO code snippets should be code that requires mod approval to get posted. I saw nothing wrong with it they way it was before -- at least everyone knew where to find them.

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

DeleteFile? Just read about it at the link I posted -- it only has one argument. How hard can that be???

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

If you just want to add a new line of text at the end of the file, then open the file for append mode. Read about the open method here. Or call seekp() to set the file pointer to end of file before writing.

If you want to add a new line somewhere else then you have to rewrite the entire file.

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

pthread.h is not natively supported on MS-Windows operating system. But you can get win32 port of that.

tux4life commented: You're doing an incredible job here :) (not sarcastic :P) +21
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why? If you are new to c++ you need to learn the language first.

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

when you type g++ main.cpp the compiler is going to compile main.cpp then attempt to link the executable. But it can't because it doesn't know anything about CBigInteger.cpp

You can solve the problem by typing this: g++ main.cpp CBigInteger.cpp

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

>>I would like to work on POSIX thread programming using TC v3.0

You can't -- that compiler is too ancient.

STL is supplied with a compiler because it is compiler-implementation specific. Your compiler doesn't have it because the compiler pre-dates STL. Upgrade to a modern compiler such as Code::Blocks or VC++ 2008 Express and you will have the STL for that compiler.

Salem commented: Well said +36
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just want to know why it gives declaration error . That is the one you said to me to adjust in my previous thread.

Take Narue's advice and fix up your code. After you do that you will be able to see the problem. I don't have the time or inclination to fix your code for you. That's you job, not mine. If you want to be a coder then you have to learn to pay attention to details and not try to do shortcuts.

You might also use a code beautifier to do it for you

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

So, let me get this straight: you told your prof that you will write a program that you have no clue how to write??? Like biting off more than you can chew?

On a scale of 0 to 100% how well do you know c++ or c ? Are you taking intro, intermediate, or advanced class ?

For the graphics I suppose wxWidgets might be the best way to go because its portable to most compilers and at least three operating systems that I know of. But wxWidgets will require a firm understanding of C language.

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

1) if you want a value between 0 and 9 then just use the mod operator int num = rand() % 10;

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

I am not studying to any books or tutorials

OMG You mean to tell us you learned to drive a car with your eyes closed :icon_eek: Get yourself an Into to C Programming book and read it Or google for online tutorials and study them It won't matter to you how old the books or tutorials are because you have a crappy teacher anyway.

Trying to learn C or C++ by steal-cut-and-paste is generally a waste of time and effort if you have no clue what the code does or how it does it.

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

Statistics class?? I'll bet you will find the answer in your textbook. It doesn't sound like a programming problem but something you can figure out in your head or with pencil & paper.

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

Just out of curiousity, what was the type of the variable, and on what platform? And related, ain't an integer increment on a PC on atomic operation?

16-bit MS-DOS 6.X which contained my own threading kernel, and it was an integer.

Incrementing an int may take more than one assembly instruction, and a task switch could take place during the execution of any given assembly instruction. Without some sort of locking mechanism there is no guarantee that the increment operator will finish before another thread tries to read/write it.

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

UNICODE characters is wchar_t, which on MS-Windows is unsigned short and on some other operating systems can be unsigned long. So why not just do something like this?

size_t i;
wchar_t buf[20];
vector<unsigned long> characters;
for(i = 0; i < characters.size(); i++)
   buf[i] = characters[i];
buf[i] = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Find out the version of windows that is running then call LoadLibrary() if its the version you want. But what about all those calls to DLL functions? Are you going to put if statements around all of those too ?

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

line 155: replace that semicolon at the end of that line with } character

and its int main not void main.

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

priyairani00> "program to swap two no. using third variable"

Maybe I misread the problem -- I thought "no." meant "not", which is why I posted the link I did.

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

>>My question is whether I need to use locks around

Yes, you need to synchronize access to that variable. There are a couple ways to do it: 1) semiphores, and 2) critical sections. Years ago I didn't do either because all it did was increment a global varialble. It cost me three days to figure out why my program randomily froze -- it was in a deadlock situation.

I would suggest you write a function to increment the variable. Inside that function you can add code to synchronize the threads. Then call that function instead of incrementing the variable all over the code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
tmp = a;
a = b;
b = tmp;

you posted wrong solution. Can not use temp variable.

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

i want to make a program in which if we input 98765 than it give output as 9 8 7 6 5
please help me

Hint: use mod operator % and division operator / in a loop

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

here is the solution to ur question

this is one way to do the problem if its for only this no.......
for all numbrs ill send u the solution in next reply

No it isn't -- it is the wrong solution. You better read the problem again.

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

How can I do that? sorry im not good with this one.

void foo()
{
   // put the code here
}

int main()
{
    switch( something )
    {
        case 1: foo(); break;
        case <all others>
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>This user has not registered and therefore does not have a profile to view.

I get this message when I click on someone's avatar.

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

Yes I know what you want but I don't know how to do it. Maybe you need to study this Flash Developer site

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

The printf() statement contains %s and %f, but there are no arguments for them

char message[] = "Hello World";
printf("%s\n", message);

In the above, mssage is passed as an argument to printf(). Your printf() needs similar arguments.

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

>>I need to put this one in my case 5
Make a separate function out of that code then just call the function from case 5. That will make your program easier to maintain.

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


csurfer :i retried gotoxy(x,y) it didnt work properly

The problem is not gotoxy() -- the problem is your code;

i am looking for a function if possible

There isn't one -- you have to write it yourself.

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

read the structure here

Your code contains a few little bugs. For example: int dd = atoi(d.c_str());

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

>>// date is a string tho?? 'dd/mm/yy'
Your program will have to parse that string to extract month, day, and year. This is not shown in the code below.

struct tm tm; // do not user a pointer here!
memset(&tm, 0, sizeof(struct tm)); // set everything to 0s
// Lets say you want to get the day of week for 
// 5 Sep 2009 (or any other day)
tm.tm_year = 2009 - 1900;
tm.tm_mon = 8; // where 0 = Jan, 1 = Feb, etc
tm.tm_mday = 5;
time_t t = mktime(&tm);
// now, hopefully, you will have day of week in the tm structure
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

very similar, but you could fill in a struct tm with the date then call mktime() to fill in the rest, including the day-of-week. Make sure you memset the struct tm with all 0's before you start or mktime() will return an error condition.

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

Not certain but WTL might be dead, and it was never officially supported by Microsoft. You are better off using wxWidgets, which is portable to several operating systems, compilers, and used by lots of programmers. There are also several tutorials that you can find with google.

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

Another question ...
If I have a class like this one, I have to manually delete created structs of CUBE right?

Yes, but why bother with those pointers? You should be able to allocate 5 of those tiny structures on the stack with no problem. Using pointers in this situation does nothing more than makes the problem more complex then it needs to be.