i was thinking of doing something like that but i was hoping there was an easier/faster way... well whatever works.
thx
i was thinking of doing something like that but i was hoping there was an easier/faster way... well whatever works.
thx
ok im at my computer now and it works better now but it doesnt strore the white spaces(ie. " "). any other ideas cause im stuped
Code:#include <iostream> void render(char [2][2], int , int); int main() { char ch = 'X'; char temp; char cArray[2][2]; int i, j; for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) cArray[i][j] = ch; //render original array for(i = 0; i < 2; ++i) { for(j = 0; j < 2; ++j) { cout << cArray[i][j]; } cout << endl; } cin >> temp; //redraw array putting space in each of // the four elements of the array, one at a time for(i = 0; i < 2; ++i) { for(j = 0; j < 2; ++j) { render(cArrray, i, j); cout << "enter any key to render a new picture" << endl; cin >> temp; } } cin >> temp; return 0; } void render(char cArray[2][2], int a, int b) { int k, L; char temp; temp = cArray[a][b]; cArray[a][b] = ' '; for(k = 0; k < 2; ++k) { for(L = 0; L < 2; ++L) { cout << cArray[k][L]; } cout << endl; } cout << endl; cArray[a][b] = temp; }
Last edited by elad; 10-04-2004 at 08:34 PM.
i kindof understand what this does and how it works...
it makes an array
XX
XX
and on input it puts a space were one of the x's are but my problem is i dont know were the spaces are going to be. ill have a file say like this
and on output it looks like thisCode:+-----------------------+ |000 | |0I0 | | *0 *********** | | ***** ***** 00| | * 000000 ****| | ** 0W00A0 00| | ************0 | |TT | |TTT TTTTTTT TTT | |TT TTTT TT TTTT | |TTT TTTTTT TTTT | | TTTT TT TTT | |MTTTTTTTTT TTTTT | +-----------------------+
the code you posted doesnt check to see what is supposed to be there and i dont know how to do that because during fin >> szMap it doesnt read the space.Code:+-----------------------+ 00||0I0||*0***********||* *******00||*000000****||* W00A000||************0||T |TTTTTTTTTTTTT||TTTTTTTTT T||TTTTTTTTTTTTT||TTTTTTT ||MTTTTTTTTTTTTTT|+------ ---------------+
sorry for taking up so much time but i am stumped
Instead of using >> to read the file one char at a time try using getline(). >> will ignore whitespace, getline() won't.
If using STL strings rather than C style strings then syntax for getline is different.Code:ofstream fout("myFile.txt"); //read line to file that contains spaces fout << "| f |\n" << endl; fout << "|**** **|\n" << endl; ifstream fin("myFile.txt"); char str[80]; int i, y; int length; int x = -1; //read file one line at a time--maintain spaces while(fin.getline(str, 80, '\n')) { //set counters for each new line read in i = 0; x++; y = 0; length = strlen(str); //extract each non-null char from line while (i < length) { myMap[x][y++] = str[i]; //display each char of each line to screen cout << str[i++]; } //add back the newline char to get proper display on screen cout << endl; }
The new line char is the default value of the third parameter for getline() so you could use
fin.getline(str, 80); if you want to.
Last edited by elad; 10-07-2004 at 11:07 AM.
thx alot for your help elad. ill try this today when i get home.