compiling error!

This is a discussion on compiling error! within the C++ Programming forums, part of the General Programming Boards category; Hi all.. i have this code here.. Code: #include <windows.h> #include <iostream.h> #include <tchar.h> //convert the string to number //udata ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    4

    compiling error!

    Hi all..

    i have this code here..

    Code:
    #include <windows.h>
    #include <iostream.h>
    #include <tchar.h>
    //convert the string to number
    //udata is string
    //udatalen is length of string
    //base is numerical base eg. for decimal it is 10
    // for hex it is 16
    //largest base supported here is upto 36
    
    int __fastcall StrToNum(const TCHAR *udata, int udatalen, int base)
    {
    	long index;
    	const TCHAR numdigits[] = TEXT("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    	long digitValue = 0;
    	long RetVal = 0;
    	TCHAR digits[sizeof(numdigits)+1];
    	TCHAR *dataVal;
    	TCHAR data[512] ;
    	//copy the data to our variable
    	_tcscpy(data, udata);
    	//convert it to upper case
    	_tcsupr(data);
    	ZeroMemory(digits, sizeof(digits));
    	//copy the number of digits supported by base in digits
    	_tcsncpy(digits, numdigits, base);
    	for(index = 0; index < udatalen; index++)
    	{
    		//is the number there
    		dataVal = _tcschr(digits, data[index] );
    		if(dataVal != 0 )
    		{
    			//if it is subtract where to start point
    			digitValue = long(dataVal - digits);
    			//increment Retval with digitvalue
    			RetVal = RetVal * base + digitValue;
    		}
    	}
    	//return the result
    	return RetVal;
    }
    
    TCHAR* __fastcall NumToStr(TCHAR *RetData, long number, int base)
    {
    	long index = 0;
    	const TCHAR numdigits[] = TEXT("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    	long digitValue = 0;
    	TCHAR digits[sizeof(numdigits) + 1];
    	TCHAR RetVal[512];
    	TCHAR CurVal = 0;	
    	ZeroMemory(RetVal, sizeof(RetVal));
    	// only base supported are from 2 to 36
    	if(base < 2 || base > 36 ) return NULL;
    	ZeroMemory(digits, sizeof(digits));
    	_tcsncpy(digits, numdigits, base);
    	while(number)
    	{
    		digitValue = number % base;
    		number = number base;
    		RetVal[index++] = digits[digitValue];
    	}
    	//since string we have got is in reversed format
    	//eg 100 will be 001 so we have to reverse it
    	//and put the value in our variable
    	ZeroMemory(RetData, _tcslen(RetVal)+1);
    	int i = 0;
    	for(index = _tcslen(RetVal) - 1; index > -1; index--)
    	{
    		//start reversing
    		RetData[i++] = RetVal[index];
    	}
    	//return the result
    	return RetData;
    }
    
    //our main function
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    	TCHAR Data[128];
    	ZeroMemory(Data, sizeof(Data));
    	//convert a number to string
    	NumToStr(Data, 1123, 10);
    	//now again convert string to number and see the result
    	cout << StrToNum(Data, _tcslen(Data), 10) << endl;
    	return 0;
    }
    but when i compile it this error msg appear to me :
    syntax error : missing ';' before identifier 'base'

    i've cheaked the place where it said that the ";" is missing but it's not!

    so pls if any1 can help me..

    and thank you very much

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    something else is missing

    number = number / base;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    change following lines to be closer to C++ standard
    Code:
    #include <iostream>
    
    	std::cout << StrToNum(Data, _tcslen(Data), 10) << std::endl;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    It would help if you could indicate which use of base in your code (there are many) which is causing the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21