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

Since you have a c++ program use c++ fstream class instead of C's FILE and associated functions. This is not very complicated to do, it just takes a little planning on what you want the file contents to look like.

float bill = 12.32; // $12.32
ofstream out("subscriptionbill.txt");
out << "This is the header\n";
out << "Monthly bill: $" << bill << "\n";
// other stuff here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to read that tutorial because there are several changes you have to make which it explains.

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

The problem is mis-matched braces '{' and '}'. delete line 119.

what is the semicolon doing on line 1?

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

Is it a C or C++ program? Do you know how to open and read text files? If you do, then just read each line and compare the first two characters with the country code.

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

maybe this will help you.

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

depends on the operating system. MS-Windows: use win32 api functions FindFirstFile() and FindNextFile()

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

>>It doesnt work...
what does that mean? what are some of the errors?

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

I can vote for Obama but never for Hilarty Klinton. A new pole today says her approval rating went down the crapper and is now only a few points from Obama.

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

>>I keep getting segmentation faults when running this program. Could anyone help me with this?

Yes -- get a clean compile before attempting to run it. your compiler should not create an executable file if it encounters syntax errors, but some older compilers will.

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

I didn't read your code, but what I would do is put the rainfall amount and month in a structure to keep them together. Then sort the structures by rainfall amounts. That makes it pretty easy to then just print the sorted array of structures and associated months.

struct rainfall
{
    double amount;
    int month;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the database.txt file is like most other text files in most cases you will just have to rewrite the whole file in order to change just one word. But, if you just want to change one word with another word of the same length you could first locate the word to be changed, back up to the beginning of that word then write the new word. Exactly how to do that depends on C or C++ language.

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

you will probably have to use one (or more) of the win32 api console functions. I haven't done it myself, but a little research in the link I provided will probably do what you want.

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

it means there is no overload >> operator for the data type of variable file. what is file. please post more code for more in-depts examination of the problem.

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

you might submit this in the C code snippets board :)

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

when you say "max width" does that mean, for example, the name is always 30 characters even when the actual name is less than that? If that's true then you can modify the structure like this.

struct person
{
    char phone_number[10];
    char name[30];
    char address[100];
    char zip[5];
};

Then read each line directly into one of those structure members

person p;

ifstream in("file.txt",ios::binary);
in.read(&p, sizeof(person));

Or, an alternative is to read the line and chop it up into fields

struct person
{
    std::string phone_number;
    std::string name;
    std::string address;
    std::string zip;
};

person p;
std::string line;
ifstream in("file.txt");

getline(in,line);
p.phone_number = line.substr(0,12);
p.name = line.substr(13,43);
p.address = line.substr(44,144);
p.zip = line.substr(145);

Now just create a vector of person structs and put all the above (lines 13 thru 17) in a loop so that it reads the whole file. You may have to adjust the substrings a little because I may not have them right, but I think you get the idea.

pulse0 commented: dude knows his sheet!! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

there should be several turorials on the net that teach you how to use the TurboC compiler. Here is one of them (I think) And here is another.

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

srand() seeds the random number generator, you should call srand() one time only and near the top of main(). Most of us use the time() function as the paramter to srand()

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

Bush and Blair are both idiots.

what else would you expect from politicians :)

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

post what you have tried.

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

see my previous answer -- it contains a link

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

>>in c++ or VC++

VC++ is a compiler, not a computer language.

found this with google

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

are you talking about this ?

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

YES -- YOUR COMPILER WILL CREATE THE EXE FILE. TELL US WHAT COMPILER AND OPERATING SYSTEM YOU ARE USING.

(Please don't use all caps like that because its like you are screeming at us, and I know you don't talk like that to your friends so why screem at us here on the net?)

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

a struct will be ok, but someone did not think very clearly when he/she created that database by making spaces the field separator when the field itself contains spaces. That will make it nearly impossible to read that file. Is there something else about the fields that distinguishes one field from another, such as are the fields all fixed-length, or surrounded by brackets as illustrated in the example you posted ?

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

SIR ANcienT DragoN thanks for the advice..

ammm do you remeber by basic programming problems.. wer the country code must be answered with their names and telephone operators..

I don't know what your problem is with strcmp() but to answer your other question, yes I do remember having a party-line telephone with a real-live operator. I also had a crank phone, which was a few years before we got dial phone in our area. I don't know what that has to do with the original question though. :-/

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

In C you can write your own strcmp() by comparing each character of the first string with each character of the second string. If the length of the two strings are not the same then they are obviously not the same thing. If they are the same length then you need to compare the two strings character-by-character.

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

iterate through the list until the current node has the same address as the initial list pointer.

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

no i dont !!

:|
if u dont want to help the n its fine !! (and i dont steal i used to beregistered on this website last year and i was making my own c++ and IM NOT a liar !! :(

Sorry, I didn't say you were lying -- I believed you when you said you were trying to cheat. :(

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

i found it somewhere and altered it...but this is not what i plan to put in my assignment...i'm trying to understand how the function works first. sorry for sounding ignorant but what do you mean by pub the getchar()

Sorry about that -- it was a typo which should have read "put " not "pub ". Example:

for( i = 0; i < sizeof(name)-1; ++i)
{
    name[i] = getchar();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you're trying to put too much at the top of that loop. Break it down, pub the getchar() inside the loop and on each loop iteration check if the value of i exceeds 19 (need one byte for the string's null terminator, or make the size of the buffer 21.

BTW: that doesn't look like it is your code -- not something a beginner would write.

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

Oh I see -- you want us to help you steal someone else's code. Not. :@

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

you probably will want to use a nice GUI package designed for gamming, like DirectX.

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

>>pz help me out
Sure, if you tell us what's wrong with the code you posted (other than being horribly formatted)

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

NodeType (line 10) has not been defined so your compiler has no clue what it is.

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

fgets() is always better than scanf() because fgets() will not accept more characters than will fit in the buffer. But neither scanf() nor fgets() will meet the requirements of your assignment. You need a function that will get only one key at a time from the keyboard so that your program can do the validations. getchar() will do that.

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

MIN and MAX won't really be of much value in your program anyway.

First use pencil & paper to find the minimum value of the 5 scores. That will give you a clue how to write the program. You would set the initial minimum value to be the value of the first number. Then look at the second number -- if it is less then the current minimum change to current minimum to be the second number. Do the same with each of the other 3 values. In your program you will have a series of 4 if statements, one if statement for each of the numbers 2 through 5.

Now do the same thing to find the maximum value.

[edit] I agree with Joe about using arrays, but only if you have learned them yet. If you can use arrays it will make the coding a lot easier[/edit]

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

I removed the smily and added the line numbers to make it a little easier to read the code.

Without actually compiling your program my guess is that the compiler doesn't like the open/close parentheses in line 16. And the keyword void in line 18 should be removed if it is trying to call that function.

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

you have changed that fill function -- your original code took a character array as the second argument, now the latest code only takes a single character. With this code you need to put that star back in.

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

serial ports, and programs that monitor them, only know about bytes of data on the port, they know nothing about what kind of data it is except monitoring programs can detect ascii text characters. If you send binary data then they can only show you the hex values, not the original data in the program that sends the data.

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

remove the star from the fill function (3d line from the bottom). you should really use [ code=c ] tags so your posted program will have line numbers and you don't have to manually add those color tags.

also, post the function printscreen(), I have no idea what it is.

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

argv is a two-diminsional array of strings. char c is only one character, not a pointer to a character array. you need to declare it as char* a in the 3d line following the declaration of main().

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

I like it too and suppose that is true for anyone with something less than perfect eyes.

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

interesitng ive been flagged...hey will one get flagged if you dont use punctuation..or is it only due to bad grammer and spelling...
and good point..

No, we don't give infractions for bad grammer -- if we did I would have been banned a long long time ago. ;) But we at least expect you to pay more attention to your typing so that we can read your posts. We all misspell words occasionally but yours goes way beyond acceptable levels.

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

fragementation of what? a memory pool? a file?

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

variable a should be declared as char*

char* a;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I hope you don't expect anyone to read that stuff you posted :-O

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

Can somene publicate a code for this solution
Thanks

Nope -- its a secret :) Seriously, you should attempt to solve it yourself and then start your own thread to ask questions.

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

The problem with your program has nothing to do with your compiler -- it was you who write the bug not the compiler. The program you posted will not work correctly with any compiler.

For a beginning class in c++ there is nothing wrong with your compiler. You will however need a better compiler when you get to more advanced stuff.

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

>>Ah, yes, about the "=="
that is a boolian operator, not an assignment operator.

you have a couple options
initialize the array with the string

char a[] = "Hello.txt";

or use strcpy

char a[15];
 strcpy(a,"Hello.txt");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Even if he had the PHP source code for that function it probably wouldn't do much good because it looks more like VB code than c or c++.

>>having it in clean c++ would be useful in future...
Of course you can write your own c++ function that simulates PHP's expode function pretty easily. $result is a c-style 2-dimensional character array, which is probably not what you want. In c++ the result array should be a vector.

Here is the start of a function

void explode( std::string str, std::vector<std::string>& array)
{
	std::string::size_type pos = str.find(' ');
	while( (pos = str.find(' ')) != std::string::npos)
	{
		// build array here

	}

}

Of course that function could return a vector, but that would be very very ineffienent because the program would have to duplicate the entire vector at least twice that I know of.