C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 12th, 2009, 02:32 PM
Shantanu_Dutta Shantanu_Dutta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 4 Shantanu_Dutta New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 18 m 34 sec
Reputation Power: 0
Unhappy HEx to Binary... plEase check d problem with This program....

/* Program to convert hexAdeCimal into binary form........ Q_13......... */

#include<stdio.h>
#include<conio.h>
#include<math.h>


int *input( int *l_pos )
{
*l_pos = 0 ;
int i = 0 , j;
int t_bit , *arr ;
printf("\n\n\tEnter the bits in hexadecimal form( 0 to 9 and A to F in CAPS ) in ") ;
printf("\n\tsequence and to quit entering , press 'RETURN' key ........ ");

printf("\n\n\tStart entering bits ............. \n\n\t");

while( ( t_bit = getche() ) != 13 )
{
*( arr + i ) = t_bit ;
*l_pos = i ;
++i ;
printf(" ");
}

return arr ;
}

int *dec_calc( int bit )
{
int j , *arr ;
bit = bit - 48 ;

for( j = 0 ; j < 4 ; j++ )
{
*( arr + j ) = 0 ;
}
j-- ;

while( bit != 0 )
{
*( arr + j ) = bit % 2 ;
j-- ;
bit /= 2 ;
}

return arr ;
}

int *alfa_calc( int bit )
{
int j = 0 , *arr ;

switch( bit )
{
case 65 : bit = 10 ; break ;
case 66 : bit = 11 ; break ;
case 67 : bit = 12 ; break ;
case 68 : bit = 13 ; break ;
case 69 : bit = 14 ; break ;
case 70 : bit = 15 ; break ;
}

for( j = 0 ; j < 4 ; j++ )
{
*( arr + j ) = 0 ;
}
j-- ;

while( bit != 0 )
{
*( arr + j ) = bit % 2 ;
j-- ;
bit /= 2 ;
}

return arr ;
}


void main()
{
clrscr();
int *arr , *f_arr ;
int l_pos , f_lpos = 0 , pos = 0 , i = 0 , j , *bin_diz , chk = 0 ;

arr = input( &l_pos ) ;

while( i <= l_pos )
{

for( j = 48 ; j <= 57 ; j++ )
{
if( *( arr + i ) == j )
{
bin_diz = dec_calc( *( arr + i ) ) ;

for( pos = 0 ; pos < 4 ; pos++ )
{
*( f_arr + f_lpos ) = *( bin_diz + pos ) ;
++f_lpos ;
}
pos = 0 ;
chk = 1 ;
break ;
}
}

if( !chk )
{
for( j = 65 ; j <= 70 ; j++ )
{
if( *( arr + i ) == j )
{
bin_diz = alfa_calc( *( arr + i ) ) ;
while( pos < 4 )
{
*( f_arr + f_lpos ) = *( bin_diz + pos ) ;
++f_lpos , ++pos ;
}
pos = 0 ;
chk = 1 ;
break ;
}
}


if( !chk )
{
for( j = 71 ; j <= 90 ; j++ )
{
if( *( arr + i ) == j )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}
}

if( !chk )
{
for( j = 97 ; j <= 122 ; j++ )
{
if( *( arr + i ) == j )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}
}

if( !chk )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}

}
}
}

chk = 0 ;
i++ ;

}

printf("\n\n\n\tAfter conversion , number in binary form is : ' " );

for( i = 0 ; i < f_lpos ; i++ )
{
printf("%d" , *( f_arr + i ) );
}
printf(" '");

getch();

}

Reply With Quote
  #2  
Old October 12th, 2009, 02:42 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
__________________

Reply With Quote
  #3  
Old October 12th, 2009, 03:01 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,256 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 20 h 36 m 23 sec
Reputation Power: 1985
Your primary problem is that your code is totally unreadable. Use code tags to preserve formatting:
Place [code] in front of your code
and [/code] after your code.

Eg:
Code:
/* Program to convert hexAdeCimal into binary form........ Q_13......... */

   #include<stdio.h>
   #include<conio.h>
   #include<math.h>


     int *input( int *l_pos )
      {
	*l_pos = 0 ;
	int i = 0 , j;
	int t_bit , *arr ;
	 printf("\n\n\tEnter the bits in hexadecimal form( 0 to 9 and A to F in CAPS ) in ") ;
	 printf("\n\tsequence and to quit entering , press 'RETURN' key ........ ");

	 printf("\n\n\tStart entering bits .............  \n\n\t");

	  while( ( t_bit = getche() ) != 13 )
	   {
	      *( arr + i ) = t_bit ;
	      *l_pos = i ;
	      ++i ;
	      printf("  ");
	   }

	  return arr ;
      }

     int *dec_calc( int bit )
      {
	int j , *arr ;
	bit = bit - 48 ;

	 for( j = 0 ; j < 4 ; j++ )
	  {
	    *( arr + j ) = 0 ;
	  }
	 j-- ;

	 while( bit != 0 )
	  {
	    *( arr + j ) = bit % 2 ;
	    j-- ;
	    bit /= 2 ;
	  }

	return arr ;
      }

     int *alfa_calc( int bit )
      {
	int j = 0 , *arr ;

	switch( bit )
	 {
	   case 65 : bit = 10 ; break ;
	   case 66 : bit = 11 ; break ;
	   case 67 : bit = 12 ; break ;
	   case 68 : bit = 13 ; break ;
	   case 69 : bit = 14 ; break ;
	   case 70 : bit = 15 ; break ;
	 }

	 for( j = 0 ; j < 4 ; j++ )
	  {
	    *( arr + j ) = 0 ;
	  }
	 j-- ;

	 while( bit != 0 )
	  {
	    *( arr + j ) = bit % 2 ;
	    j-- ;
	    bit /= 2 ;
	  }

	return arr ;
      }


     void main()
      {
	clrscr();
	int *arr , *f_arr ;
	int l_pos , f_lpos = 0 , pos = 0 , i = 0 , j , *bin_diz , chk = 0 ;

	 arr = input( &l_pos ) ;

	while( i <= l_pos )
	 {

	    for( j = 48 ; j <= 57 ; j++ )
	     {
	       if( *( arr + i ) == j )
		 {
		   bin_diz = dec_calc( *( arr + i ) ) ;

		   for( pos = 0 ; pos < 4 ; pos++ )
		    {
		      *( f_arr + f_lpos ) = *( bin_diz + pos ) ;
		      ++f_lpos ;
		    }
		   pos = 0 ;
		   chk = 1 ;
		   break ;
		 }
	     }

	  if( !chk )
	   {
	    for( j = 65 ; j <= 70 ; j++ )
	     {
	       if( *( arr + i ) == j )
		 {
		   bin_diz = alfa_calc( *( arr + i ) ) ;
		   while( pos < 4 )
		    {
		      *( f_arr + f_lpos ) = *( bin_diz + pos ) ;
		      ++f_lpos , ++pos ;
		    }
		    pos = 0 ;
		   chk = 1 ;
		   break ;
		 }
	     }


	    if( !chk )
	     {
	      for( j = 71 ; j <= 90 ; j++ )
	       {
		if( *( arr + i ) == j )
		 {
		   printf("\n\n\tHexadecimal bits entered are not valid ! ");
		   chk = 1 ;
		   break ;
		 }
	       }

	     if( !chk )
	      {
	       for( j = 97 ; j <= 122 ; j++ )
		{
		 if( *( arr + i ) == j )
		  {
		   printf("\n\n\tHexadecimal bits entered are not valid ! ");
		   chk = 1 ;
		   break ;
		  }
		}

	       if( !chk )
		{
		   printf("\n\n\tHexadecimal bits entered are not valid ! ");
		   chk = 1 ;
		   break ;
		}

	      }
	     }
	   }

	  chk = 0 ;
	  i++ ;

	 }

	printf("\n\n\n\tAfter conversion , number in binary form is : ' " );

	 for( i = 0 ; i < f_lpos  ; i++ )
	  {
	   printf("%d" , *( f_arr + i ) );
	  }
	 printf(" '");

	getch();

      }


Now, just what problem is it that you are having with this code? First you give us an unreadable listing and then you make us play guessing games with you. That kind of nonsense will only earn you severe flamings. Be nice with us and we will be nice with you and even help you. Play stupid tricks on us and we will have no reason to be nice with you.

If you are having a problem, then you must tell us what that problem is.

Does it not compile? If not, then what compiler error messages do you get?

Does it compile and crash when you run it? Then you must tell us that fact, as insignificant as you might feel that it is. If it only crashes after you have provided certain input (eg, runs fine until you have entered all the inputs it asks for), then you need to tell us that as well.

Does it compile and run, but give you unexpected results? Then you must tell us what results you had expected and what you got instead. Explicitly.

Most of us have our day jobs and little spare time to help out here. If you just want to waste our time, we won't. If you really do want help with something, then you must help us to help you. Capice?


I will hazard a guess that your program crashes. I noticed that in most of your functions you make this declaration:
int *arr ;
and then later in the function you make an assignment such as:
*( arr + j ) = 0 ;
without ever having assigned any value to the pointer, arr, thus making it an uninitialized pointer.

Since arr is a local variable, its contents are initially pure garbage; ie, whatever just happens to have been last written to that location -- "garbage" is the actual term used. Which means that if you try to use that garbage as a pointer value with which to write to a location in memory, then you could be trying to write to anywhere on the system. Since your program does not have access to the vast majority of memory locations on your system, your program should crash due either to an access violation or a segmentation fault, depending on your OS.

Never attempt to use an uninitialized pointer. For that matter, did your compiler issue any warnings? Some compilers will try to warn you about using an uninitialized variable. Treat your compiler's warnings as if they were error messages. A warning usually indicates that you've written something that's confusing it; a confused compiler can be a dangerous thing.


PS
Just what is this program trying to do? Does it accept an input string that represents a hex value and print an output string that represents the equivalent binary value?

Your code looks far too cumbersome and overly complex for performing such a simple task. Converting between hex and binary is so simple that a human can perform it on sight, unlike converting between either number base and decimal which does require some hand calculations. Why else do you think that octal and hex are so popular? Write out all 16 hex digits and their binary equivalents and think about it.

An explanation of exactly what you're trying to do and how (ie, comment your code so that it explains what that code is doing) would help out immensely.


PPS
You might want to make arr an parameter of the functions that the calling function will pass in. Since it's a pointer, any changes you make within the function to what it points to will be remembered outside the function. Then you must be sure that the calling function passes an actual existing array to those functions it calls -- HINT: main does not declare an actual arr array either.

Last edited by dwise1_aol : October 12th, 2009 at 03:22 PM.

Reply With Quote
  #4  
Old October 12th, 2009, 04:27 PM
jwdonahue's Avatar
jwdonahue jwdonahue is offline
Bellevue WA, USA
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 3,398 jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 48 m 17 sec
Reputation Power: 886
d problem with u program is d same as d problem with your post. It sucks!

I recommend that you fix both of them.
__________________
My worst nightmare was a pointless infinite loop.
Work in progress; don't poke the curmudgeon!
http://www.odonahue.com/

Reply With Quote
  #5  
Old October 12th, 2009, 07:34 PM
Shantanu_Dutta Shantanu_Dutta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 4 Shantanu_Dutta New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 18 m 34 sec
Reputation Power: 0
Unhappy hexadecimal to Binary...............

fIrst of all M xtremely sorry for not mentioning wHat I wanted to ask.................

The main problem with the program is it does not give the desired output..........

eg.
if input is 2C6B............ it will simply convert 2 to 0010 and will exit the main loop instead of continuing the loop...............

that is, instead of giving an output for 2C6B as 0010110001101011............ it simply gives 0010 with an additional statemnt "Null pointer assignment"...............

I am executing the program in Turbo C++ compiler............

Now if I trace the program by pressing 'F7'....... it simply does whatever the program is meant to do......... according to logic..........

2)........ Y dis program is cumbersome because doing the program using a list of switch cases is too basic..............

what i want to do here is........ it will take the input of the hexadecimal bits in its ASCII format........
eg. for 2C6B.... it wud be 50 67 54 66................... then it will simply compare where does the range falls for each bit ( for alphabet and integer ( 0-9 and A-F ) and will convert each bit to its binary form.
the problem lies now. once it converts, it will store in a temporary unassigned array of the respective functions after which it will return the function to the main where it will transfer the bits contained in the arr which is now in bin_diz to f_arr................

once it completes this procedure for each bit..... it will simply print f_arr... which wud be its answer..............

But, the main issue here is though it does d process , but only once..... i.e. for the very first bit................ there r no errors also...........

so i m completely confused of what problem could the program have..............

Hope i was able to give a fair idea bout mY program and you could help me solve my problem.............

tHanx............

Shantanu....................

Reply With Quote
  #6  
Old October 12th, 2009, 07:43 PM
Shantanu_Dutta Shantanu_Dutta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 4 Shantanu_Dutta New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 18 m 34 sec
Reputation Power: 0
Unhappy hexadecimal to Binary...............

/* Program to convert hexAdeCimal into binary form........ Q_13......... */

#include<stdio.h>
#include<conio.h>
#include<math.h>


int *input( int *l_pos ) // function to input hex bits into a temorary array "arr"
{
*l_pos = 0 ;
int i = 0 , j;
int t_bit , *arr ;
printf("\n\n\tEnter the bits in hexadecimal form( 0 to 9 and A to F in CAPS ) in ") ;
printf("\n\tsequence and to quit entering , press 'RETURN' key ........ ");

printf("\n\n\tStart entering bits ............. \n\n\t");

while( ( t_bit = getche() ) != 13 )
{
*( arr + i ) = t_bit ;
*l_pos = i ;
++i ;
printf(" ");
}

return arr ;
}

int *dec_calc( int bit ) // function to convert bits (0-9) to its equivalent binary form and store it in arr
{
int j , *arr ;
bit = bit - 48 ;

for( j = 0 ; j < 4 ; j++ )
{
*( arr + j ) = 0 ;
}
j-- ;

while( bit != 0 )
{
*( arr + j ) = bit % 2 ;
j-- ;
bit /= 2 ;
}

return arr ;
}

int *alfa_calc( int bit ) // function to convert bits (A-F) to its equivalent binary form and store it in arr
{
int j = 0 , *arr ;

switch( bit )
{
case 65 : bit = 10 ; break ;
case 66 : bit = 11 ; break ;
case 67 : bit = 12 ; break ;
case 68 : bit = 13 ; break ;
case 69 : bit = 14 ; break ;
case 70 : bit = 15 ; break ;
}

for( j = 0 ; j < 4 ; j++ )
{
*( arr + j ) = 0 ;
}
j-- ;

while( bit != 0 )
{
*( arr + j ) = bit % 2 ;
j-- ;
bit /= 2 ;
}

return arr ;
}


void main()
{
clrscr();
int *arr , *f_arr ;
int l_pos , f_lpos = 0 , pos = 0 , i = 0 , j , *bin_diz , chk = 0 ;

arr = input( &l_pos ) ; // input function called and the array stored in arr..........

while( i <= l_pos )
{

for( j = 48 ; j <= 57 ; j++ )
{
if( *( arr + i ) == j )
{
bin_diz = dec_calc( *( arr + i ) ) ; // dec_calc() func called and the values stored in bin_diz

for( pos = 0 ; pos < 4 ; pos++ ) // transfering elements from bin_diz to f_arr which is the final array......
{
*( f_arr + f_lpos ) = *( bin_diz + pos ) ;
++f_lpos ;
}
pos = 0 ;
chk = 1 ;
break ;
}
}

if( !chk )
{
for( j = 65 ; j <= 70 ; j++ )
{
if( *( arr + i ) == j )
{
bin_diz = alfa_calc( *( arr + i ) ) ; // alga_calc() func called and the values stored in bin_diz
while( pos < 4 ) // transfering elements from bin_diz to f_arr which is the final array......
{
*( f_arr + f_lpos ) = *( bin_diz + pos ) ;
++f_lpos , ++pos ;
}
pos = 0 ;
chk = 1 ;
break ;
}
}


if( !chk ) // error checkin ( if bits betwn ( G -Z ) )
{
for( j = 71 ; j <= 90 ; j++ )
{
if( *( arr + i ) == j )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}
}

if( !chk ) // error checkin ( if bits betwn ( a - z ) )
{
for( j = 97 ; j <= 122 ; j++ )
{
if( *( arr + i ) == j )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}
}

if( !chk ) // error checkin ( if any other possibilities)
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}

}
}
}

chk = 0 ;
i++ ;

}

printf("\n\n\n\tAfter conversion , number in binary form is : ' " );

for( i = 0 ; i < f_lpos ; i++ )
{
printf("%d" , *( f_arr + i ) );
}
printf(" '");

getch();

}

Reply With Quote
  #7  
Old October 12th, 2009, 07:45 PM
Shantanu_Dutta Shantanu_Dutta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 4 Shantanu_Dutta New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 18 m 34 sec
Reputation Power: 0
Unhappy

Code:

/* Program to convert hexAdeCimal into binary form........ Q_13......... */

#include<stdio.h>
#include<conio.h>
#include<math.h>


int *input( int *l_pos ) // function to input hex bits into a temorary array "arr"
{
*l_pos = 0 ;
int i = 0 , j;
int t_bit , *arr ;
printf("\n\n\tEnter the bits in hexadecimal form( 0 to 9 and A to F in CAPS ) in ") ;
printf("\n\tsequence and to quit entering , press 'RETURN' key ........ ");

printf("\n\n\tStart entering bits ............. \n\n\t");

while( ( t_bit = getche() ) != 13 )
{
*( arr + i ) = t_bit ;
*l_pos = i ;
++i ;
printf(" ");
}

return arr ;
}

int *dec_calc( int bit ) // function to convert bits (0-9) to its equivalent binary form and store it in arr
{
int j , *arr ;
bit = bit - 48 ;

for( j = 0 ; j < 4 ; j++ )
{
*( arr + j ) = 0 ;
}
j-- ;

while( bit != 0 )
{
*( arr + j ) = bit % 2 ;
j-- ;
bit /= 2 ;
}

return arr ;
}

int *alfa_calc( int bit ) // function to convert bits (A-F) to its equivalent binary form and store it in arr
{
int j = 0 , *arr ;

switch( bit )
{
case 65 : bit = 10 ; break ;
case 66 : bit = 11 ; break ;
case 67 : bit = 12 ; break ;
case 68 : bit = 13 ; break ;
case 69 : bit = 14 ; break ;
case 70 : bit = 15 ; break ;
}

for( j = 0 ; j < 4 ; j++ )
{
*( arr + j ) = 0 ;
}
j-- ;

while( bit != 0 )
{
*( arr + j ) = bit % 2 ;
j-- ;
bit /= 2 ;
}

return arr ;
}


void main()
{
clrscr();
int *arr , *f_arr ;
int l_pos , f_lpos = 0 , pos = 0 , i = 0 , j , *bin_diz , chk = 0 ;

arr = input( &l_pos ) ; // input function called and the array stored in arr..........

while( i <= l_pos )
{

for( j = 48 ; j <= 57 ; j++ )
{
if( *( arr + i ) == j )
{
bin_diz = dec_calc( *( arr + i ) ) ; // dec_calc() func called and the values stored in bin_diz

for( pos = 0 ; pos < 4 ; pos++ ) // transfering elements from bin_diz to f_arr which is the final array......
{
*( f_arr + f_lpos ) = *( bin_diz + pos ) ;
++f_lpos ;
}
pos = 0 ;
chk = 1 ;
break ;
}
}

if( !chk )
{
for( j = 65 ; j <= 70 ; j++ )
{
if( *( arr + i ) == j )
{
bin_diz = alfa_calc( *( arr + i ) ) ; // alga_calc() func called and the values stored in bin_diz
while( pos < 4 ) // transfering elements from bin_diz to f_arr which is the final array......
{
*( f_arr + f_lpos ) = *( bin_diz + pos ) ;
++f_lpos , ++pos ;
}
pos = 0 ;
chk = 1 ;
break ;
}
}


if( !chk ) // error checkin ( if bits betwn ( G -Z ) )
{
for( j = 71 ; j <= 90 ; j++ )
{
if( *( arr + i ) == j )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}
}

if( !chk ) // error checkin ( if bits betwn ( a - z ) )
{
for( j = 97 ; j <= 122 ; j++ )
{
if( *( arr + i ) == j )
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}
}

if( !chk ) // error checkin ( if any other possibilities)
{
printf("\n\n\tHexadecimal bits entered are not valid ! ");
chk = 1 ;
break ;
}

}
}
}

chk = 0 ;
i++ ;

}

printf("\n\n\n\tAfter conversion , number in binary form is : ' " );

for( i = 0 ; i < f_lpos ; i++ )
{
printf("%d" , *( f_arr + i ) );
}
printf(" '");

getch();

}


fIrst of all M xtremely sorry for not mentioning wHat I wanted to ask.................

The main problem with the program is it does not give the desired output..........

eg.
if input is 2C6B............ it will simply convert 2 to 0010 and will exit the main loop instead of continuing the loop...............

that is, instead of giving an output for 2C6B as 0010110001101011............ it simply gives 0010 with an additional statemnt "Null pointer assignment"...............

I am executing the program in Turbo C++ compiler............

Now if I trace the program by pressing 'F7'....... it simply does whatever the program is meant to do......... according to logic..........

2)........ Y dis program is cumbersome because doing the program using a list of switch cases is too basic..............

what i want to do here is........ it will take the input of the hexadecimal bits in its ASCII format........
eg. for 2C6B.... it wud be 50 67 54 66................... then it will simply compare where does the range falls for each bit ( for alphabet and integer ( 0-9 and A-F ) and will convert each bit to its binary form.
the problem lies now. once it converts, it will store in a temporary unassigned array of the respective functions after which it will return the function to the main where it will transfer the bits contained in the arr which is now in bin_diz to f_arr................

once it completes this procedure for each bit..... it will simply print f_arr... which wud be its answer..............

But, the main issue here is though it does d process , but only once..... i.e. for the very first bit................ there r no errors also...........

so i m completely confused of what problem could the program have..............

Hope i was able to give a fair idea bout mY program and you could help me solve my problem.............

tHanx............

Shantanu....................
Comments on this post
sizablegrin disagrees: Save your SMS talk for your phone.

Reply With Quote
  #8  
Old October 12th, 2009, 09:17 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,256 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 20 h 36 m 23 sec
Reputation Power: 1985
OK, you used code tags, but you posted unformatted code! The reason for using code tags is to preserve your code's formatting. Putting unformatted code in code tags is nothing but malicious compliance. So why are you now deliberately insulting us?


Second, what does arr point to? Tell me specifically what arr points to. In other words, show me explicitly where you assign a value to arr that causes it to actually point to something.

Until you post code that we can read, we can't even begin to try to figure out why it terminates prematurely. I'm immensely surprised that it doesn't crash and barf in your lap. Unless it does, but you just didn't notice. If I can remember that many decades ago, Turbo C++ would report the runtime error that would cause the program to crash.

If the IDE doesn't report that, then open a command prompt (AKA "console", AKA "DOS window") and run the .EXE file from the command line. cmd.exe will report a crash.


PS
I remember that some of Borland's products included a debugger. I forget when the C++ line started including it, so I don't know whether your version has it. You might check it out and give it a try. That way, you can step through your code line-by-line and see exactly what's going on.

Last edited by dwise1_aol : October 12th, 2009 at 09:22 PM.

Reply With Quote
  #9  
Old October 13th, 2009, 08:47 AM
MadDogBrown MadDogBrown is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Posts: 837 MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 43 m 22 sec
Reputation Power: 526
My desire to protect an industry already in decline from a further influx of under-qualified entrants (complete with impressive, un-verifiable overseas references) far overwhelms any desire to provide help in this situation.

Reply With Quote
  #10  
Old October 13th, 2009, 08:59 AM
Nyan Nyan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 337 Nyan User rank is Sergeant Major (2000 - 5000 Reputation Level)Nyan User rank is Sergeant Major (2000 - 5000 Reputation Level)Nyan User rank is Sergeant Major (2000 - 5000 Reputation Level)Nyan User rank is Sergeant Major (2000 - 5000 Reputation Level)Nyan User rank is Sergeant Major (2000 - 5000 Reputation Level)Nyan User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 15 m 47 sec
Reputation Power: 45
You really have serious problem. Take a look at input() ,dec_calc(),alfa_calc() functions. You are not initializing arr (pointer to integer) . And what's 13 ??
Comments on this post
dwise1_aol agrees: In each of my replies, I told him about arr. The guy is just incapable to taking any hint.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > HEx to Binary... plEase check d problem with This program....

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap