Thread: dynamic memory allocation on demand

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2
    the code is smth like that:

    input is 0..9 & a..b (not checks others)
    counts the base of the 'number' (max 36 - 'z'), and writes down that 'number' is in decimal

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    int main()
    
    {
    	char s[256];
    	int base=0,basemax=0,i;
    	long decimalone=0;
    	scanf("&#37;s",&s);
    
    	for (i=0;i<strlen(s);i++)
    		{
    
    		if (s[i]>=97)
    			base=s[i]-86;
    		else
    			base=s[i]-47;
    
    		if (base>basemax)
    		basemax=base;
    
    		}
    				for (i=0;i<strlen(s);i++)
    { if (s[i]>=97)
    decimalone+=(s[i]-87)*pow(basemax,(strlen(s)-1-i));
    else decimalone+=(s[i]-48)*pow(basemax,(strlen(s)-1-i));
    }
    
    
    		printf("\n\n%d",basemax);
    
    		printf("\n\n%d",decimalone);
    		return 0;
    }
    Last edited by oilrg; 12-02-2007 at 03:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  3. Dynamic memory allocation...
    By dicorr in forum C Programming
    Replies: 1
    Last Post: 06-24-2006, 03:59 AM
  4. dynamic memory allocation w/o new
    By bd43274 in forum C++ Programming
    Replies: 11
    Last Post: 02-15-2006, 02:12 AM
  5. dynamic memory allocation - Please help
    By Space_Cowboy in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2002, 05:20 PM