Thread: Compiling in Unix vs Visual C++

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    81

    Compiling in Unix vs Visual C++

    Does anyone know what the differences are between compiling in Unix and Visual C++?

    My code works in Visual C++ but it doesn't in Unix. When compiling it says:

    In function 'void RuleTwo(basic_string<char,string_char_traits<char> ,__default_alloc_template<false,0>>,
    basic_string<char,string_char_traits<char>,__defau lt_alloc_template<false,0>>)'

    and

    unused varialbe 'int len' (within the same function)

    Anybody know how I could fix this? Thanks in advance. Here is the code if you need it:

    Code:
    void RuleOne(string word, string target1)
    
    // Pre-condition:	String has been entered by user and starts with the
    //					following letters: TH, CH, SH, PH, WH, QU.
    
    // Post-condition:	Returns single string to the screen with the first two
    //					letters removed from the front and added to the end of
    //					the word and the letters AY added to the end of the string.
    
    {
    	string temp;
    	int len = word.length()-1;   // Index of last character
    
    	if (target1=="TH" || target1=="th" || target1=="tH" || target1=="Th" ||
    		target1=="CH" || target1=="ch" || target1=="cH" || target1=="Ch" ||
    		target1=="SH" || target1=="sh" || target1=="sH" || target1=="Sh" ||
    		target1=="PH" || target1=="ph" || target1=="pH" || target1=="Ph" ||
    		target1=="WH" || target1=="wh" || target1=="wH" || target1=="Wh" ||
    		target1=="QU" || target1=="qu" || target1=="qU" || target1=="Qu")
    	{
    		temp = word.substr(2,len);
    		word = temp + target1 + "AY";
    		cout << word << endl;
    
    	} // End if
    
    } // End function RuleOne
    
    void RuleTwo(string word, string target2)
    
    // Pre-condition:	String has been entered by user and starts with the following
    //					letters: A, E, I, O, U.
    
    // Post-condition:	Returns original string to the screen with the letters AY
    //					added after the string.
    
    {
    	string temp;
    	int len = word.length()-1;   // Index of last character
    
    	if (target2=="A" || target2=="a" ||
    		target2=="E" || target2=="e" ||
    		target2=="I" || target2=="i" ||
    		target2=="O" || target2=="o" ||
    		target2=="U" || target2=="u")
    	{
    		word += "AY";
    		cout << word << endl;
    
    	} // End if
    
    } // End function RuleTwo
    
    void RuleThree(string word, string target1, string target2)
    
    // Pre-condition:	String has been entered by user and does not fit RuleOne
    //					or RuleTwo
    
    // Post-condition:	Returns single string to the screen with the first letter
    //					removed from the front and added to the end of
    //					the word and the letters AY added to the end of the string.
    
    {
    	string temp;
    	int len = word.length()-1;   // Index of last character
    
    	if (!(target1=="TH" || target1=="th" || target1=="tH" || target1=="Th" ||
    	      target1=="CH" || target1=="ch" || target1=="cH" || target1=="Ch" ||
    		  target1=="SH" || target1=="sh" || target1=="sH" || target1=="Sh" ||
    		  target1=="PH" || target1=="ph" || target1=="pH" || target1=="Ph" ||
    		  target1=="WH" || target1=="wh" || target1=="wH" || target1=="Wh" ||
    		  target1=="QU" || target1=="qu" || target1=="qU" || target1=="Qu" ||
    		  target2=="A" || target2=="a" ||
    		  target2=="E" || target2=="e" ||
    		  target2=="I" || target2=="i" ||
    		  target2=="O" || target2=="o" ||
    		  target2=="U" || target2=="u"))
    
    	{
    		  target2 = word.substr(0,1);
    		  temp = word.substr(1,len);
    		  word = temp + target2 + "AY";
    		  cout << word << endl;
    	
    	} // End if
    
    } // End function RuleThree
    
    
    void KeepGoing()
    
    // Pre-condition:	User has entered a choice.
    
    // Post-condition:	Starts the program again if user enters Y or y.  Ends the
    //					program if user enters anything else.
    {
    	char ch;
    	string word, target1, target2;
    	cout << "\nWould you like to continue? (Enter Y for yes): ";
    	cin >> ch;
    	
    	if (ch=='Y' || ch=='y')
    	{
    		cout << "\nPlease enter another word: ";
    		cin >> word;
    		cout << word << " = ";
    
    		target1= word.substr(0,2);
    		target2= word.substr(0,1);
    		
    		RuleOne(word, target1);
    		RuleTwo(word, target2);
    		RuleThree(word, target1, target2);
    		KeepGoing();
    	
    	} // End if
    
    	else
    	{
    		cout << "\nThank you for using this program.\n\n";
    	
    	} // End else
    
    } // End function KeepGoing
    
    
    int main()
    {
    	string word;
    	string target1, target2;
    
    	cout << "This program will translate one word from English to PigLatin.\n\n";
    	cout << "Please enter a word: ";
    	cin >> word;
    	cout << word << " = ";
    
    	target1= word.substr(0,2);
    	target2= word.substr(0,1);
    
    	RuleOne(word, target1);
    	RuleTwo(word, target2);
    	RuleThree(word, target1, target2);
    	KeepGoing();
    
    	return 0;
    
    } // End Main

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    That should just be an error. But this sort of thing has nothing to do with Unix as much as it has to do with your compiler. This doesn't even have anything to do with ANSI-C either. Some compilers like to tell you that you are using wasteful code. You may want to use Cygwin if you are compiling for Unix and Windows. VC++ is okay but it was designed for M$ OS's. You should be able to fix your problem by commenting out the declaration if int len or use it somewhere in the function.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    81

    Thank you

    It was just wasteful code indeed. Seems the Unix compiler is a little fussier than Visual C++. I'm just not used to that particular compiler but I'm learning thanks to people like you.

    I will look through the posts, as I've seen many compiler questions, to find out where I can find Cygwin in order to use it for future coding.

    I have a feeling that I may be back with ANSI-C questions later though.... we shall see...

    Thanks for the advice! It is always very much appreciated!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. compiling C code at visual C++ 6.0
    By hattusili in forum C Programming
    Replies: 7
    Last Post: 02-10-2008, 01:26 PM
  3. Visual C++ 6.0 : linking / compiling problems
    By sh4k3 in forum Tech Board
    Replies: 2
    Last Post: 06-16-2007, 12:20 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM