const int MAX=200;
	char line[MAX];
	char s2[MAX];

	inf.getline(line,MAX);

	for(;;)
	{	
		for(int i=0; i < MAX ; i++)
		{
			if (line[i]=='\0')
				break;
			else if ( line[i] != ' ')
				strcat(s2, line[i]);
		}
	}

hello, I have a question. I'm trying to have the loop process words in the array "line" and copy the words onto another array s2. however, this keeps giving me the error
" .\reformat.cpp(71) : error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'"

what am i doing wrong? Thank you!

strcat() concantinates strings, not single characters. you can do a simple assignment for that

char s2[MAX] = {0};
for(int i=0; i < MAX ; i++)
{
    if (line[i]=='\0')
         break;
    if ( line[i] != ' ')
          s2[i] = line[i];
}

The above will fix the syntax error but not the logic error. All the above does is extract the first word from the input string. What are you going to do the the rest of the string?

I'm trying to copy all the lines/character in a file into an array so that i can reformat the text. Thank you for your help!!!

First since this is c++ you should use std::string, not c-style character arrays because it will make your life a lot simpler. The class std::stringstream will help you split the line into individual words, and finally you can use std::vector to same the list of all words in the file. If you search this c++ board for stringstream you will find examples of how do do all that because it was posted just the other day.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.