chrjs 42 Junior Poster in Training

You could try making the main function a friend of the DisplayController class, although that is more of a work-around than an actually solution.

chrjs 42 Junior Poster in Training

Are the ALLEGRO_BITMAP, ALLEGRO_EVENT, ALLEGRO_EVENT_QUEUE identifiers macros, or just normal types?

chrjs 42 Junior Poster in Training

Although Ancient Dragon's solution should work, the problem with your original code is probably with the byte order. Most modern computers have little endian byte orders meaning that the bytes are stored least significant to most significant, e.g. a 16-bit integer of 0x1234 would be stored as the 8-bit bytes 0x34,0x12. You read the bytes with a big endian byte order, which is most significant to least significant. Basically, you need to flip the subscripts on line 9.

chrjs 42 Junior Poster in Training

It's a gross generalization, but in my experience, if the publisher is out of India, it raises red flags; I have yet to see a decent beginner's book on programming come out of India. Can you learn from these books? Absolutely. Will you pick up an excessive number of bad habits along the way? Very likely.

Go here and find a book that's either recommended or highly recommended.

Isn't that like kind of general? Thats a huge list of books, and it seems to me like the majority of them are C++ oriented, not C oriented. In my opinion, "The C Programming Language" by Brain Kernighan and Dennis Ritchie is probably one of the best books on ANSI C.

chrjs 42 Junior Poster in Training

In string constants enclosed in quotes, the backslash\ is used as an escape sequence so you can put in characters that you normally couldn't type into the string, like \" or \' so you have to use the escape sequence for the \ in the file name which is just \\

chrjs 42 Junior Poster in Training

yah..=D that works for me..
and a other question.. if my system is 32bit, i coulnt use 64bit registers?

Then just replace "%%rax" with "%%eax" and "movq" with "movl"

wildplace commented: :D thx +2
chrjs 42 Junior Poster in Training

Like WaltP said, you should have the command write to a file and then read from that file. You should probably use the "system" function in stdlib.h. You don't have to "embed" a shell inside of your C program. Also, the good thing about the find command is it lists all the files it finds line by line, so you only need to use a function like "fgets" to read the filenames from the file generated from find's output.

chrjs 42 Junior Poster in Training

Wrong forum, this should be in Hardware & Software->Microsoft Windows->Windows Vista and Windows 7.

chrjs 42 Junior Poster in Training

In your while statement on line 35 you are using a %s to get input for a float, I don't know what result this will produce from fscanf, but it is possible that the loop is never entered and that the calday is never called, and even if it is you probably would receive weird results anyway. You should probably use a %f instead of a %s.

chrjs 42 Junior Poster in Training

the std::getline function puts its output into a std::string, the std::ifstream::getline function puts its output into a char*. You should call getline like fp.getline(buffer, SIZE);

chrjs 42 Junior Poster in Training

Although if you don't want to use vectors, the problem probably is that at line 26, you are changing the value of the local variable p in the function increaseArraySize, which doesn't change the value of the p in addEntry. You should pass p as a reference like void increaseArraySize(phoneBook *& p, int &numLines, int a)

chrjs 42 Junior Poster in Training

No he means not agree because of the following line:

cin >> input[1] >> input[2] >> input[3] >> input[4] >> input[5];

This is saying that the array has up to 6 elements but it is defined as int input[5]. This means that calling input[5] will cause the program to crash because it is outside the bounds of the array. It should be this:

cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4];

Also, using this

int something;
   cin>>something;

is dangerous because if the user enters a character instead of an int the program will freak out.

Um, no. Ancient Dragon said "The parameters to the function in lines 5 and 27 to not agree." However, you said that he is using "not agree" to refer to the line "cin >> input[1] >> input[2] >> input[3] >> input[4] >> input[5];", which is line 18.

chrjs 42 Junior Poster in Training

By "not agree" he meant that the parameter at line 5 is an int and at line 27 it is an array of ints. That is probably what caused the undefined reference error.

chrjs 42 Junior Poster in Training

NCTKID1, what is the purpose of your three posts on this thread? To me they don't seem like they would help anyone, considering all you are doing is post some code that is a complete alternative to the original posters code. And even if it did help him, did you consider that this thread was started more than 3 years ago?

chrjs 42 Junior Poster in Training

When broken down, a char is just a single byte, that is the reason why it only takes char* pointers, because char is a just a byte. You can just cast your double* to a char* pointer and change the size argument so that it accounts for the size of a double. Like this:

//this will write a single double in binary format
outfile.write( (char*)(&a_double), sizeof(double) );

This isn't converting from binary to ASCII, or anything of the sort, it is just treating the 8-byte (on most computers) double as 8 characters (bytes).

chrjs 42 Junior Poster in Training

The first example you gave does not actual write anything in binary, ios_base::binary does not actually change how the data is written to the file. It is just an indicator that you are going to put binary data into the file, but outfile << 1234 << " " << 5678 << " " << 9012 << endl; will still produce the output 1234 5678 9012 (although they might have some '.0's after them cause they are doubles), not those numbers binary representations.

All your second example does is copy data in one file into another, in which case the file being a binary file or a text file would not matter.

chrjs 42 Junior Poster in Training

Hmm... I didn't know ANSI C was changed from C90 to C99, I guess I am more than 10 years behind the times...

chrjs 42 Junior Poster in Training

you are reading the binary representation of an integer instead of the decimal representation of an integer. result = fread(&num_cust[0], sizeof(int), 1, fp); reads however many bytes the size of an integer is (on most computers, that is 4 bytes.) So assuming a 4 byte integer, the function would read the bytes represented by the characters "3\n27" into the variable result.

You should use the fscanf function for getting input that would be a decimal number like fscanf(fp, "%d", &result);

prgrmmngaccnt commented: thanks for solving the problem. +0
chrjs 42 Junior Poster in Training

you should probably use && instead of || on the 4th line. Also, on the 8th line you should calculate how many minutes to add, instead of just adding 1 (the user could enter 1000 seconds or something like that.) and after that you should change the seconds to fit within 0 <= seconds <= 59

chrjs 42 Junior Poster in Training

I understand it became legal to do so in C99.

Even though it is legal in C99, its not legal in standard C. C code isn't as portable by writing declarations halfway through the code.

chrjs 42 Junior Poster in Training

at line 42, you can't declare a variable in c in the middle of the program, all variable declarations have to be at the beginning of the code. Also, you can't use a non-constant variable to initialize the size of the array inside brackets. Even if you could do that, you shouldn't have a pointer that points to arrays of characters, you never allocated any memory to that pointer, thats why you are getting the segmentation fault.

chrjs 42 Junior Poster in Training

I don't know much about libQGLViewer, but you could try keeping viewer local and just making a variable that points to viewer global, and call updateGL using that pointer.

chrjs 42 Junior Poster in Training

If you want to check if the user's input is valid, you can just put a do-while loop around the code that gets the input from the user.

chrjs 42 Junior Poster in Training

in C, the keyword const doesn't exist, but it does in C++.

#define is used often in C to declare a name for a value that doesn't ever change throughout the execution of the program. This makes it easier to change values that are used over and over again.

chrjs 42 Junior Poster in Training

This is the function with the warning, to my understanding

char *num2Pstring( number )
	int 	number;
{
	int place = 0;
	int hundreds, tens, units;
	char string[5];

	string [ place++ ] = 'P';
	hundreds = number / 100;
	number = number - ( hundreds * 100 );
	tens = number / 10;
	number = number - ( tens * 10 );
	units = number;

	if ( hundreds != 0 )
		string[ place++ ] = hundreds + 48;
	if ( ! ( ( hundreds == 0 ) && ( tens == 0 ) ) )
		string[ place++ ] = tens + 48;
	string[ place++ ] = units + 48;  
	string [ place ] = 0; 
	return( string );
}

At line 6 you should declare string as a char* and allocate memory the array using malloc(/*bytes to allocate*/) to remove the warning message

chrjs 42 Junior Poster in Training

The if statement and do-while statements are mixed up.
Basically, you wrote

do {
	if (/*expression*/)
	{
		/* some code */
	} while ( /*expression*/ );
}