Link to home
Start Free TrialLog in
Avatar of sundeepgopal
sundeepgopal

asked on

returning a string from a function

Hi experts,

I want to send a string to function and after using that it should return a string to the main function.  I was not able to do that. Could you guys please help me ???
When i trace it , the flow control never goes to second function (i.e., opcodes).  

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

void main()
{
  char *opcodes(char* );
  char *s;
  s=opcodes("100011");
  printf("%s",s);
}


char *opcodes(char a)
{
  int i;
  char *opco[][2]=
  {
      {"SUB",  "100010"},
      {"SUBU", "100011"},
      {"ADD",  "100000"},
      {"ADDU", "100001"},
      {"AND",  "100100"},
      {"OR",   "100101"},   //R Instructions where opcode="000000" and functions codes are here
      {"NOR",  "100111"},
      {"XOR",  "100110"},
      {"SLT",  "101010"},
      {"SLL",  "000000"},
      {"SRL",  "000010"},
      {"SRA",  "000011"},
      {"JR",   "001000"},
      {"BEQ",  "000100"},
      {"BNE",  "000101"},
      {"BGEZ", "000001"},  //BGEZ and BLTZ have same opcode but rt's are different
      {"BGTZ", "000111"},
      {"BLEZ", "000110"},
      {"BLTZ", "000001"}, //I instructions with their opcodes
      {"SLTI", "001010"},
      {"ADDI", "001000"},
      {"ADDIU","001001"},
      {"J",    "000010"}, //JUMP opcodes
   };

   for (i=0;i<=22;i++)
  {
   if(opco[i][1]==a)
   return(opco[i][0]);

  }
}
Avatar of sundeepgopal
sundeepgopal

ASKER

thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of PaulCaswell
PaulCaswell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi sundeepgopal,

>>   if(opco[i][1]==a)
This compares the two pointers, not the strings themselves.

Paul
thanks paul