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]);

  }
}
C

Avatar of undefined
Last Comment
sundeepgopal

8/22/2022 - Mon
sundeepgopal

ASKER
thanks in advance
ASKER CERTIFIED SOLUTION
PaulCaswell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
PaulCaswell

Hi sundeepgopal,

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

Paul
sundeepgopal

ASKER
thanks paul
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck