troubleshooting Question

returning a string from a function

Avatar of sundeepgopal
sundeepgopal asked on
C
4 Comments1 Solution341 ViewsLast Modified:
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]);

  }
}
ASKER CERTIFIED SOLUTION
PaulCaswell

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros