Matrix Issue >.>

I am trying to read words from a file, and print them to another file, but this time I want them to be printed by columns not by rows. Let me show you the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <fstream>

using namespace std;

int main()
{
	char dic[101][101];
	int i,j=1;
	
	ifstream in("A1.in");
	ofstream out("A1.out");
	
	for(i=1;i<=101;i++)
	{
		if (dic[i][j]=='.')
		{
			j++;
			continue;
		}
		else
			in >> dic[i][j];
	}
	
	for(i=1;i<=101;i++)
	{
		if (dic[i][j]=='.')
		{
			j++;
			out << "\n";
		}
		else
			out << dic[i][j];
	}
	
	in.close();
	out.close();
	
	return 0;
}


What I want as result:

1
2
3
4
5
6
A1.in
code.
desk.
chair.
roof.
mood.


1
2
3
4
5
6
A1.out
c d c r m
o e h o o
d s a o o
e k i f d
    r


Could you pretty please help me ?
Last edited on
Read the file into a vector of strings (one for loop). You'll have to remove the '.'s manually. Then find the length of the longest string (one for loop). Then you have to do
1
2
3
4
5
6
7
8
9
10
vector<string> vec;//all the lines
int len;//longest line
for(int i = 0; i < len; i++){//this is how many lines you want to write
   for(int j = 0; j < vec.length(); j++){//for each input line
      if(vec.[j].length() > i)//if the line is long enough
         cout << vec[j][i];//print the ith char on it
      else cout << ' ';
   }
   cout << '\n';
}
May I ask what does the declaration vector<string> vec do ? I haven't work with such command until now. Also, the length usage doesn't need any other library included ?

Thanks for help.
Last edited on
I beg an forum administrator close Framework's account. Thanks for the understanding!
I am here to ask for help, not to have a war with that person who is full of himself.

So, coming back ON-topic, can someone explain me in detail what does the following instruction do vector<string> vec ?

Thanks in advance.
Last edited on
Framework you are not welcome to reply on my topic. I knew you as a very good, kind and helpful person. That was like 1 year ago. You were helping me and lots of other people. I dont know what happend to you, but it's easy to tell that something bad happened in your private life. I'm not doctor, nor your friend, so I will stop here. Even if I'm not your friend, I just hope God will help you find the right way... Goodluck.
Last edited on
Lol
Last edited on
@jumper007...

We think that Framework's account has been compromised recently. We're not at all sure what/who caused it, but we're trying to ignore him.

This probably isn't the real Wazzak/Framework. I suggest ignoring him.

-Albatross
@Albatross. You are right. This is not the real Frame. I hope everthing will get back to normal asap...

Now coming back xD what does vector<string> vec do ? XD
Framework (1762) I'd like to let you know that I traced your ip :] The hacking may begin!

The hacker is going to be hacked! (For your PC's sake, I hope you got a good antivirus :))
Last edited on
@jumper007
It creates a vector of strings! I'm guessing you haven't worked with templates yet, so the syntax might be a bit unfamiliar. The following links should help...

http://www.cplusplus.com/doc/tutorial/templates/
http://www.cplusplus.com/reference/stl/vector/

Happy programming!

-Albatross
@ Albatross
Thanks a lot. I am gonna study it :)
Last edited on
Topic archived. No new replies allowed.