This is a piece of code that I can't seem to get right. Hehe.
I've initialized the string "sym" to have the values '0' and '0'. I then call the function "cnvrt" and use "sym" in the parameter(not so sure if that's the right term) of "cnvrt". Since strings are passed by reference, the value of "sym" after I put it in "cnvrt" should be ' ' and '\0'; at least that's what I think.
That is why I need help on this one. It's part of my machine problem and I really have to finish it. Tnx a lot..

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void cnvrt(char s_Hex1[2])
{
	char s_Hexdecitable[16][6] = {{' ', '0', '@', 'P', '`', 'p'},
                                                    {'!', '1', 'A', 'Q', 'a', 'q'},
                                                    {'"', '2', 'B', 'R', 'b', 'r'},
                                                    {'#', '3', 'C', 'S', 'c', 's'},
                                                    {'$', '4', 'D', 'T', 'd', 't'},
                                                    {'%', '5', 'E', 'U', 'e', 'u'},
                                                    {'&', '6', 'F', 'V', 'f', 'v'},
                                                    {'\'', '7', 'G', 'W', 'g', 'w'},
                                                    {'(', '8', 'H', 'X', 'h', 'x'},
                                                    {')', '9', 'I', 'Y', 'i', 'y'},
                                                    {'*', ':', 'J', 'Z', 'j', 'z'},
                                                    {'+', ';', 'K', '[', 'k', '{'},
                                                    {',', '<', 'L', '\\', 'l', '|'},
                                                    {'-', '=', 'M', ']', 'm', '}'}, 
                                                    {'.', '>', 'N', '^', 'n', '~'},
                                                    {'/', '?', 'O', '_', 'o', ' '}};
	char row, col;
	row = s_Hex1[1];
	col = s_Hex1[0] - 2;
     	switch(row){
          	 case 'A':{
                	 row = 9; 
                	 break;
           	}       
        	 case 'B':{
                	 row = 10;
            	    	 break;
            	}
    	     case 'C':{
                	 row = 11;
                 	 break;
           	}
             case 'D':{
                	 row = 12;
                  	 break;
          	}
             case 'E':{
                	 row = 13;
                 	 break;
           	}
             case 'F':{
                	 row = 14;
                 	 break;
            	}     
     	}
     	s_Hex1[0] =  s_Hexdecitable[row][col];
	s_Hex1[1] = '\0';
}

int main()
{
	char sym[2] = {'0', '0'};
	cnvrt(sym);
        return 0;
}

after passing sym to cnvrt() value of
row='0' and
col='0'-2= '.' (ascii of '0' is 48 and 48-2=46 which is ascii of character '.')
so ultimately
s_Hexdecitable[row][col]=s_Hexdecitable[48][46]

(since it is index which should be integer hence that will be converted to integer.

since 48,46 is more than the dimension of ur array hence it will yield garbage value.

The ascii value of '0' is 48. So the values of row and col on lines 24 and 25 are 48 and 46 respectively. That means the switch on line 26 doesn't do anything because the value of 48 is not one of the case statements. Next, line 52 reads outside the bounds of the array dimensions, so it will return some random value.

[edit]^^^ What Danger said[/edit]

Also,

I've initialized the string "sym" to have the values '0' and '0'.

Then it's not a string, it's a character array. strings must end with '\0' (or 0).

I then call the function "cnvrt" and use "sym" in the parameter(not so sure if that's the right term) of "cnvrt".

Yes, that's the correct term.

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.