![]() |
|
#1
|
|||
|
|||
Writing an Output fileI'm having problems writing an output file from a permutation function. The file takes in 6 letters and then makes all possible permutations, but I need those permutations to be outputted to a file because I'm going to need to compare them to another file. My current code only outputs what I believe is the last permutation charater to the file. If anyone can help me figure out where the error lies it would be really appreciated. Here is the code:
I CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Writing an Output fileQuote:
First of all, by default, the "cin>>next" operation skips whitespace, so it can never return a '\n' character. If you want to test with fewer than six characters, you could use cin.get(). Many C++ programmers would use getline(), but it's OK with get(). Anyhow, I think debugging will go a lot faster if you try it with two or three characters to begin, and then work your way up to six. CPP / C++ / C Code:
Secondly, I would either initialize the array to all zeros, or, more likely, I would explicitly put the terminating '\0' byte in the array so that I could print out the contents for debugging purposes: CPP / C++ / C Code:
The extra statements that I put for debugging just might be helpful. Thirdly, when you are putting stuff out to the file, you reopen it as a brand-new file each time. I would probably try debugging by putting stuff to cout to make sure the permutation was working, then re-introduce the file operations after I was happy with the results: CPP / C++ / C Code:
Then when you put the file stuff back in, note that if you want to add something to a file rather than opening it up anew (and therefore overwriting its previous contents), you use the ios::app mode: CPP / C++ / C Code:
And, by the way, did you wonder why your screen blanked out when you ran the program? (I did.) Look carefully at the output stuff in your original perm. (Why is there "cout << " there?) Regards, Dave [c] |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| run script command on ns2.26 | newbie06 | Computer Software Forum - Linux | 65 | 19-Aug-2009 08:50 |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| After execution - Error cannot locate /Skin File? | WSCH | C++ Forum | 1 | 05-Mar-2005 21:03 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
| CD Buring Failed | skanth2000 | Computer Hardware Forum | 1 | 15-Nov-2003 04:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The