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

moved to C board.

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

Post some real code you are having problems with so that we know exactly what you are trying to do.

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

>>sorry guys! I will fix that later.... I just copy the code in POST #1

Oh, I see. Then you want to copy the code from post #1, click the link that says "Toggle Plain Text". Then right-click inside the box, in the menu select "Select All", do it again and select "Copy". That puts it into the clipboard so that you can paste it anywhere you want.

>>I logout immediately without reviewing that code.
DON'T EVER DO THAT. Always review what you posted so that you can correct mistakes (I do it all the time :) ) Next time your post will just get deleted.

>>try it and you will see the results..
Why should I bother ? Re-post it correctly and I might.

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

Hi all.

Could anyone please put comments on each command that Ancient Dragon posted? It's just to be sure what each of them means.

I'm having trouble compiling this:

//blabla

    char OutFile[100];

    FILE* fp;
    sprintf(OutFile,"wind%d", date);
    fp = fopen(OutFile,"w");
    OutFile << "Longitude\tLatitude\tDirection\tVelocity\n";//here appears an error!!
//blabla

Maybe there is another way of writing information into the output file.

thanks!

I didn't write that. The line you marked with error is C++ code, not C code. You can't put c++ code in a c program.

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

<<*A = *B;
*B = *A;

Looks like you are trying to swap the pointer addresses? Then you need a temporary holding pointer, and that function must return a pointer since that's how you declared it.

PointerA operator = (const& PointerA * C, const& PointerA *D)
{
    PointerA* A = C;
    C = D;
    D = A;
    return C;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can i not delete the data from the text file directly? Overwrite it maybe?

The only way to delete a line in a text file is to rewrite the entire file, leaving out the line to be deleted.

Also, don't put the £ symbol in the file because it just makes reading the file a little more difficult.

line 34 doesn't really do anything because temp is overwritten on every loop iteration. You need to add more code inside that loop to populate that array of structures as the rows are read. You can't wait until after reading is done. For example. At the end of the loop below the variable counter will contain the number of rows read from the file. You will want to use that variable throughout the rest of the program to determine how many valid entries there are in the array. When deleting a row make sure the row number to be deleted does not exceed the value of counter, which will probably be less than 100. When adding a new row you have to add it to the first unused entry (counter+1) and increment counter variable.

#include <sstream> // required for stringstream class

if(myfile.is_open())
{
    int counter = 0;
    while(getline(myfile,line))
    {
          stringstream str(line);
    // now split the line into its individual parts
    // These are listed in the same order as they appear
    // in the structure.
          str >> entries[counter].ID
               >> entries[counter].date
               >> entries[counter].item
               >> entries[counter].category
               >> entries[counter].price;
    }
    myfile.close(); …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) Move the structure definition in lines 49-55 up above any functions, about line 13 because it makes better overall program organization. Most programs are organized to have all includes at the top followed by structures, classes, enumerations (in any order or in header files), globals and function prototypes. You have most of that already, just need to move the structure declaration to the top of the program.

line 34: why??

lines 64-88: It might be better to use a switch statement instead of all those if statements.

line 294: The array only has 100 elements, numbered 0 to and including 99. So the statement should be < 100, not <= 100.

The only other comment about that function is you need to clear the last structure by setting all strings to empty strings.

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

try to compiled it on my pc it was successfully compiled as an exe file.

Maybe you did successfully compile the code you have on your computer, but you won't the code that you posted, because all of those # characters. Copy the code you pasted back to your compiler and try to compile it, I'm 100% certain that the compiler will hate it.

It almost looks like you copied that code off some web site because I have seen those # characters somewhere before. If you copied the code from a text file residing on your computer those # characters should not have appeared.

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

2. lack of "()" in sizeof(line)

your code: while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */

should be --> while ( fgets ( line, sizeof(line), file ) != NULL ) /* read a line */

What? sizeof doesn't always require (), but I like to use them anyway myself. There was nothing wrong with the syntax. Read this

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

you are doing too much work!

#include <iostream>
using namespace std;
#pragma warning(disable: 4996)

const int HEIGHT = 5;
const int LENGTH = 4;
int main()
{
   int **pointerArray, *dummyPointer;

    pointerArray = new int* [HEIGHT];

    for (int cnt = 0; cnt < HEIGHT; cnt++)
	    pointerArray[cnt] = new int [LENGTH];

    for (int cnt1 = 0; cnt1 < LENGTH; cnt1++)
    {
        dummyPointer = pointerArray[cnt1];
	    for (int cnt2 = 0; cnt2 < HEIGHT; cnt2++)
	    {
	        *dummyPointer = cnt2;
	        dummyPointer++; 
	    }
    }

   
    for (int cnt1 = 0; cnt1 < LENGTH; cnt1++)
    {
        dummyPointer = pointerArray[cnt1];
	    for (int cnt2 = 0; cnt2 < HEIGHT; cnt2++)
	    {
	        cout << *dummyPointer << endl;
	        dummyPointer++; 
	    }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I came across this thread from a few years ago. I was thinking I would like to put a small image in my signature, tried it but it didn't work.

Is the policy (no gifs in sigs) still valid? Or did I do it wrong? Honestly I haven't see anyone here with a gif in their signature. The one I had in mind is pretty small, not animated -- nothing to the extent that people were talking about in that thread.

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

I put your program all in one file and here is the result (using VC ++ 2008 Express)

#include <ctype.h>
#pragma warning(disable: 4996)


void strToUpper(char *str)
{
	int i = 0;
	while(str[i] != '\0')
	{
		str[i] = toupper(str[i]); //reset bit 5
        ++i;
	}
}

int getCommandId(char *word)
{
	FILE *fp;
	char buf[256];
	char *tok;
	int i = 0;

	fp = fopen("commands.txt", "r");
	if(fp == NULL)
		return -1;
	
	strToUpper(word);
    i = 0;
	while(fgets(buf, 255, fp) != NULL)
	{
        strToUpper(buf);
		tok = strtok(buf, " ");
        ++i;
		while(tok != NULL)
		{
			if(strcmp(tok, word) == 0)
				return i;

			tok = strtok(NULL, " ");
		}
	}

	return 0;
}

int main(int argc, char* argv[])
{
	char word[256];
	int id;

	strcpy(word, "move");
	strToUpper(word);
	printf("%s", word);
	id = getCommandId(word);

	if(id == -1)
		perror("Error");
	else if(id == 0)
		printf("No such command.");
	else
		printf("ID: %d\n", getCommandId("move"));

	getchar();
	return 0;
}

The main problem with the program is that main() calls getComandId() twice. In the printf() line, instead of calling getCommandId() again (line 60 of the code I posted) just use the return value from the previous call.

getCommandId() also needs to close the file before exiting, which I did NOT correct.

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

>>str[i++] &= 0xDF; //reset bit 5
Programming is not about trying to be cute, but about writing code that you and everyone else in the world can easily comprehend. str[i] = toupper(str[i]); ++i;

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

Oh what a joy Microsoft compilers are to work with. One click of the [ key and I found the problem. Mismatched { and } on line 214. There is another one, but I'm not telling where it is -- that's for you to find. :)

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

>>so English experts we want to listen from your expertise.
That will not be me, but I will give you my opinion anyway :)

There are hundreds of English language dialects, even in the USA there are quite a few. Fortunately, most of them can be understood by most people, and only accents are the main difference. A good wiki explanation is here

AFAIK there are two common forms of the English language -- American English and British English. All other dialects are based on one of those two. The same word used commonly in UK may mean something entirely different than in the USA. The expression "knock me up" comes to mind, I learned that one the hard way when I lived temporarily in England during the 1970s. Others that come to mind are "boot", "bonnet", "rubber".

And to make it even more difficult, the English language is scattered with words from other languages, such as French and German.

For those reasons it must be exceedingly difficult for non-English speaking people to learn the English language.

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

in main.cpp, delete line 2 #include "hello.cpp". NEVER EVER include a *.c or *.cpp file in another one like that. If main.cpp needs to know about that function, then just use extern keyword, like this:

#include <iostream>
using namespace std;

extern int funny_words();
// blabla

Also, funny_words() is declared to return an integer. You must add code to do that on line 16. If you don't need it to return anything then change it to void function void funny_words()

Salem commented: You should have mentioned the "#define GEQUAL" horror as well :) +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what is sem_t ? Probably a typedef of an int. You should be able to typecase it. printf("Estão a decorrer %d chamadas\n", (int)var_telefonista);

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

must be some other problem. This compiles for me. Also note that you do not have to manually add the line numbers -- [code=c] ... [/code] will do that.

int n = 0;
void *var_telefonista = (void *)&n;

 void *print(void *nume)
 {
 
   while(1){
//     pthread_mutex_lock(&mutex);
     int x =  *(int*)var_telefonista;
     printf("Estão a decorrer %d chamadas\n", *(int*)var_telefonista);
     printf("O número de operadores livres é %d\n", (*(int *)nume - x));
//     printf("Chamadas em espera %d\n",espera);
//     pthread_mutex_unlock(&mutex);
//     sleep(5);
  }
 }

 int main()
 {

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

why bother using strncat() just to concantinate a single character? Seems such a waste of time. And in that loop K[k][0] = '\0'; is always deleting the previous entry in the array.

A much easier, and IMO, better approach to the problem is just keep another counter where the new character should go

k=0;
   int n = 0;
   memset(K, 0, sizeof(K)); // clear the array
  while(((c = getc(f)) != EOF) && (t = getc(p)) != EOF){
     K[k][n++] = c ^ t & 0xFF;
     if(t == ' '||  t == '\n')
     {
	k++;
        n = 0;
     } 

  }

You could also save a lot of memory by making array K an array of pointers or a linked list, then allocating the space needed for each word, so that a word that is only one character doesn't occupy 256 bytes of memory.

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

The error is signed in the line that i write ERROR is here.

Well Duuuah :)

This will also work -- assuming nume is really an int pointer. If its not an int pointer than this will not work. printf("O número de operadores livres é %d\n",(*(int *)nume - x))

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

Well, its not fixed yet afterall. I just attempted to visit DaniWeb and FF crashed on me again. I wonder if DaniWeb has any flash content?

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

Which line are you getting that error on?

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

I haven't found a bit tiny thing of democracy yet...

Why would you? DaniWeb is not a democracy. If you want to think of it in political terms then it would be a dictatorship, as all web sites are.

For all it is worth, issues like double-posting shouldn't be existing for good visibility/functionality. But, one good reason isn't enough.

We delete double posts whenever found.

Also, comments in reputation should allow a feedback to be fair. That's very rustic.

So, just make another rep post.

I think user feedback should be taken into account.

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

After allocating the memory for the array you can not increment or decrement the pointer. When you do, you destroy the memory that was allocated because the pointer to the original memory is lost.

If you want to increment/decrement pointers, then create another pointer for that purpose, but leave the original pointer unchanged.

tux4life commented: I can't explain this in a better way :) ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

PointerArray is a two-dimensional array, right ? You have to allocate both dimensions

PointerArray = new int *[HEIGHT]; // allocate an array of int pointers
for(int i = 0; i < HEIGHT; i++)
    PointerArray[i] = new int[LENGTH];

The above will allocate what would be statically allocted like this: int PointerArray[HEIGHT][LENGTH];

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

Welcome to DaniWeb. Sorry, but this is not the place to post encryped messages or c++ code.

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

>>can u help me
Yes, but you have to explain a little more what you want and how we can help. For example, what is "final database ER" ?

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

For MS-Windows you will need this. But you don't need to write a driver to do what you want -- there are win32 api functions that let your program monitor the file system. Here is a start how to do that.

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

If that worked then you created a windows CLR project.

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

Thanks people -- glad to know its not just me. There was an update installed a day or so ago so hopefully it fixed the problem. FF hasn't died on me since then.

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

Are you using managed code (CLR) ? Had you pressed F1 (Help) and searched for MessageBox you would have found the below in about 10 seconds. But instead you have wasted a couple days.

For CLR programs

MessageBox::Show( "Hello World -- this is a Message Box", "Help",
            MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There's nothing to it MessageBox(NULL, "Hello This is a message box", "Help", MB_OK);

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

How is that array declared in the class? Array's can't be initialized like that after they have been declared. After the array has been declared that is has to be initialized the hard way, like below.

TravelVoucher::exchItems[0]="Dinner for TWO at BestFood Restaurant";
TravelVoucher::exchItems[1]= "Buffet for TWO at EatTillDrop";

TravelVoucher::exchItems[2]= "Ticket for TWO for Singapore Flyer";
TravelVoucher::exchItems[3]= "High Tea for TWO at TeaForYou";

If it was not originally declared in the class, then try this:

const char* array[]={"Dinner for TWO at BestFood Restaurant", "Buffet for TWO at EatTillDrop", "Ticket for TWO for Singapore Flyer", "High Tea for TWO at TeaForYou"};

return array[i]; // this is dangerous if the value of i > 3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I tried to compile using VC+ 2008 Express:

your program has a lot of unused variables that you need to clean up to prevent millions of warnings about it.

It also contains a couple real syntax errors. But you probably missed your compiler's error messages with all those warnings about unused variables.

line 556: what is setup ?

line 608: wnat is noplay ?

[edit]Ok noplay is a label. But you can get rid of it by removing the goto statement.

function checkblack() does not return a string. That could be a huge problem for anything calling that function.

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

"Hail to the Chief" sounds forth as the President of the United States arrives at any formal occasion

Thought you might enjoy this version. :)

http://video.google.com/videoplay?docid=6185603495801760929

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

What I have done is create a structure with all the information I want exchanged between the two windows. When the 2nd window is created pass a pointer to the structure to the 2nd Window so that it can fill in the information. Once Window 1 regains control it will have the information in the structure.

Another approach is for Window #2 to send a private message to Window #1 that contains the information. Then Window #1 can update itself with the info. This works well when there is only a small amount of text to be transferred between the windows.

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

It works, and may be efficient, but difficult to explain. Here is an easier version to follow

char *trim (char *str)
{
    char *ibuf = NULL, *obuf = NULL;
    if( str != NULL)
    {
        ibuf = str;
        // find first non-space character
        while( isspace(*ibuf) )
            ibuf++;
        // anything to do?
        if( ibuf > str)
        {
            // shift everything left to fill up
            // leading spaces
            memmove(str,ibuf, strlen(ibuf)+1);
        }
        // find last character
        obuf = ibuf = str + strlen(str) - 1;
        // back up to first non-space character
        while( isspace(*obuf) )
            --obuf;
        // if there were trailing spaces
        if( obuf != ibuf )
            *(obuf+1) = 0;
    }
    return (str);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post CToken.h

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

>>Would it just be done like this
No. See my previous example

strcpy(output,name) // strcpy() only for the first one
strcat(output,addr); // strcat() for all the others
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>#include <afxres.h>

That header file is only useful in Microsoft MFC programs. For Dev-C++ you might as well delete it.

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

>>I need to copy the name, addr, telephone, carinfo, payment array to the output array. How would I go about doing that

use strcat() to concantinate c-style character arrays. You just need to make sure the destination string is big enough to hold all the strings you want to put into it.

char destination[255] = {0};
strcpy(destination "Hello ");
strcat(destination, "World");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Create 5 integers that will accumulate the counts for each vowel.

print prompt to enter string
accept keyboard input into std::string or character array variable

loop through each character in the string
beginning of loop
   test for vowel
   if 'a' then increment a-counter
   else if 'e' then increment e-counter
   etc. for each vowel
end of loop

print the value of each vowel counter
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>assignment makes integer from pointer without a cast

I don't get that error when I compile it with vc++ 2008 Express.

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

Its probably the DLLs. What version of os did you compile it on, and is it different than the one you tried to run it on?

In the compiler's install directory you will see a folder named "redist", which contains the DLLs you may have to install with your program.

On my computer he is here:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT

Be very careful with those DLLs -- don't just copy them to windows directory, but copy them to the same folder that your program is in. If that does not fix the problem, then those DLLs will not help.

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

I'm partial to the use of "strftime()"

And I did all that in only three lines of executable code ;)

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

The lady that made an ass of Simon Cowell! What a talented woman :) :)

http://www.youtube.com/watch?v=RxPZh4AnWyk&NR=1

I've watched that clip 5 or 6 times and am amazed each time I watch it.

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

>>I need to write a program

Ok, so write it :)

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

What the hell are you talking about :S

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

I think Microsoft Installer is free, although I have never used it.

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

use the functions in time.h to get a struct tm, then use sprintf() to format the filename

char filename[255];
struct tm* tm;
time_t now;
now = time(0); // get current time
tm = localtime(&now); // get structure
sprintf(filename, "file_%02d%02d%04d", tm->tm_mon+1,
    tm->tm_day, tm->tm_year+1900);